tanthammar / tall-forms

Laravel Livewire (TALL-stack) form generator with realtime validation, file uploads, array fields, blade form input components and more.
https://github.com/tanthammar/tall-forms/wiki
MIT License
694 stars 86 forks source link

Selecting values with javascript on multiselect field #95

Closed pitsail closed 2 years ago

pitsail commented 2 years ago

Let's say select field looks like this:

<select name="form_data.branches" OTHER_PROPERTIES multiple>
    <option value="1">Branch 1</option>
    <option value="2">Branch 2</option>
    <option value="3">Branch 3</option>
</select>

When values are picked in a standard cliking way everything is fine, selected ones are passed on form submit. But when i use javascript like:

document.getElementById('form_data.branches').options[1].selected = true;

values are displayed as selected but they are not passed on submit.

What am i missing? BTW this problem concerns all form fields.

tanthammar commented 2 years ago

It's because all forms are Livewire forms. You don't set Livewire properties in Javascript that way.

Please read the Livewire documentation on JavaScript interactions.