Livewire form submit select option name='' not working
here is my code -
Blade -
<form wire:submit.prevent="save(Object.fromEntries(new FormData($event.target)))">
<select name='parent_id'>
<option value=''> select </option>
<option value='a'> a </option>
<option value='b'> b </option>
</select>
<input type='text' name='name'>
<input type='text' name='address'>
</form>
Controller -
public function save($formData){
dd($formData);
}
Here when I dd() the input text i got but not the select data. I dont understant where i did wrong here?
@mahbubrn Why not you try with wire:model approach?
<form wire:submit.prevent="save">
<select name="parent_id" wire:model="parent_id">
<option value="">Select</option>
<option value="a">A</option>
<option value="b">B</option>
</select>
<input type="text" name="name" wire:model="name">
<input type="text" name="address" wire:model="address">
<button type="submit">Submit</button>
</form>
public function save()
{
dd([
'parent_id' => $this->parent_id,
'name' => $this->name,
'address' => $this->address,
]);
}
@tisuchi yes, i know that data binding. but for some reason i need that way.
@tykus I need the select data from name=" " value, not wire:model=" ".
I found the some solution from here
https://github.com/livewire/livewire/issues/313
but its working for input text. select name='' not working.
@mahbubrn you still do not explain why you need this approach; the Github thread you reference is really old?
What else are you not sharing; the code snippet you shared above works in Livewire 3?
@tykus its complicated to explain why i need this. so i skipped this.
and yes its works in livewire 3
Why is there a wire.submit.prevent? shouldn't it be wire.submit?
Please or to participate in this conversation.