0

I have a Datepicker with custom attribute. I give this attribute with JavaScript, and I try to pass this att with JavaScript to my Livewire controller. This attribute is added with JavaScript because I'm using a library. So I have access to this attribute in JavaScript. I want to give it to the variable I created in class.

<input id="birth-date" type="text" autocomplete="off" placeholder="dd/mm/yyyy" 
       class="form-control air-datepicker" data-position="bottom right"/>

<i class="btn btn-primary btn-sm text-light" id="date_start_btn" 
   onclick="startday()">save date</i>

<script>
    function startday() {
        var startday = document.getElementById('birth-date').getAttribute('data-jdate');
        document.getElementById('birth-date').value = startday;
        document.getElementById('date_start_btn').classList.remove("btn-primary");
        document.getElementById('date_start_btn').classList.add("btn-success");
    }
</script>

I want to send startday to my Livewire component to use.

3
  • The input #birth-date does not have a custom attribute data-jdate. If it did, use dataset Commented Apr 25, 2022 at 8:54
  • This attribute is added with JavaScript because I'm using a library. I have access to this attribute in JavaScript. I want to give it to the variable I created in class Commented Apr 25, 2022 at 8:58
  • Make sure startday runs after the library does. Commented Apr 25, 2022 at 9:05

1 Answer 1

1

Its worked for me!!

<input id="birth-date" wire:model="date" type="text"  autocomplete="off" placeholder="dd/mm/yyyy" class="form-control air-datepicker" data-position="bottom right" />
    
<script>
                                
function startday() {
var startday = document.getElementById('birth-date').getAttribute('data-jdate');
document.getElementById('birth-date').value = startday;
    
@this.set('date', startday);
                               document.getElementById('date_start_btn').classList.remove("btn-primary");
document.getElementById('date_start_btn').classList.add("btn-success");
}
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.