F
Filament15mo ago
jals65

Hidden reactive input loses value when it change.

Hi, i'm using a hidden input in a component to set a value trow js to save it in bbdd when the form is saved. The problem is when this value is changed and livewire render the view, the value="" attribute is deleted, but the value continues storaged in state.
5 Replies
jals65
jals65OP15mo ago
All hidden inputs loses value attribute when 1 is reloaded. This issue occurs since I update to v3
toeknee
toeknee15mo ago
How are you defining hidden inputs And should you be passing them as hidden? and not as mutatebeforesave?
jals65
jals65OP15mo ago
Hidden::make($this->getStatusComponentName()) ->default(array_keys($this->options)[0]) ->reactive() ->extraAttributes([ 'data-progressChildStatus' => $this->getName() ]) And i'm changing the value by JS. Getting the element and doing a element.value = "new value" By doing that, as the component is reactive and changes its value, livewire makes a render. That's when you delete the value. The first time the page is load, the value is created correctly with the value that i define in default() But the problem is when i change it @toeknee I adding 'value' => $getState() in the Hidden field component view. It works. vendor/filament/forms/resources/views/components/hidden.blade.php
<input
{{
$attributes
->merge([
'id' => $getId(),
'type' => 'hidden',
$applyStateBindingModifiers('wire:model') => $getStatePath(),
'value' => $getState()
], escape: false)
->merge($getExtraAttributes(), escape: false)
->class(['fi-fo-hidden'])
}}
/>
<input
{{
$attributes
->merge([
'id' => $getId(),
'type' => 'hidden',
$applyStateBindingModifiers('wire:model') => $getStatePath(),
'value' => $getState()
], escape: false)
->merge($getExtraAttributes(), escape: false)
->class(['fi-fo-hidden'])
}}
/>
toeknee
toeknee15mo ago
I was going to say, you are clearing them on the live and not setting them again, if you want to set defaults you can but you tend to do that in the form fill method/
jals65
jals65OP15mo ago
Ok, thanks
Want results from more Discord servers?
Add your server