so, the array isn't empty if user has change the default option ? will it return not an empty array ? is it return as you want when you click all option and selected all the select box or radio ?
Livewire getting default values of an input array
I have the following setup in my Cart.php file :
public $options = [];
public function addToCart()
{
foreach ($this->options as $key=>$value){
dump($key . $value);
}
$this->options = [];
}
And the inputs are set up like this (custom added fields that are different for each product. Can be checkbox, select or text input as well) :
<input type="number" min="0" id="{{ $field->name }}" wire:model="options.{{ $field->id }}" placeholder="{{ $field->name }}" required/>
The problem is : When user doesn't select anything, options array returns empty. I know this is expected behavior since I'm setting it this way in the Cart.php, but there are default values in the inputs (like the first option in a select input, default state of a checkbox etc) and when user clicks Add to cart button without changing the default selected values it returns empty and I can't process the data if it doesn't exist.
Update : I'm pretty sure it's not the best way to do this but I solved it by giving each field type a hardcoded default value. With all due respect to livewire, it's just stupid that we can't get the default data (that is right there in the HTML) to the component file.
Please or to participate in this conversation.