Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  134] [ 4]  / answers: 1 / hits: 6244  / 4 Years ago, sun, november 29, 2020, 12:00:00

I have a text input field which works great if I update it myself when typing inside it, however, what I need is to have this input field be populated with data from javascript, rather than the user.
This is my input field


<input type="text" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="images" wire:model="images">

This is what happens if I type "123" in the input field, I get this for the input field's value:


enter


However when I update it using javascript, document.getElementById("images").value = "Hello"
The input field is populated with the new data:
enter


But it doesn't make a new fetch call to get the data and the last one is with the "123" data that was inserted without javascript...


enter


Any idea of how it can get the data after updating the input's value from javascript?


More From » laravel

 Answers
3
<script>
document.addEventListener('livewire:load', function () {
@this.set('images','Hello');
//console.log('Hello');
});
</script>


Make a public property name 'images, initiate it in the mount. I hope it will solve your problem. Let me know.


[#2207] Tuesday, November 24, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
aileent questions
;