How are you actually submitting the form; I suspect it is not properly using wire:submit?
How to remember form data in livewire component when validation fails?
I have a form in classic blade file and validate data in external request file. I have an "old" operator in forms and when validation fails, data I typed remains in this form and I see the error, then I can fill the form correctly and save data.
But I use a livewire component in this form, it's checkbox. If I check then the optional form will appear and I can fill this optional form. Everything works fine BUT when validation fails this checkbox is unchecked and optional form is empty (there is no 'old' directive, and I have to fill this form once again). How to leave this checkbox checked and - the more important - remember data in optional livewire form when validation fails?
Blade file (task-form.blade.php) with livewire include:
...
<div class="md:col-span-4">
@livewire('nexttask', ['status_types' => $status_types, 'whoisnext_types' => $whoisnext_types, 'action_types' => $action_types, 'activity_types' => $activity_types])
</div>
...
This livewire (netxttask) file is:
<div>
@if($hide)
<div class="flex items-center mb-4">
<input id="next_task" name="next_task" wire:click="show" type="checkbox">
<label for="next_task">Create next task</label>
</div>
@endif
@if($show)
//some form and THIS FORM IS EMPTY WHEN VALIDATION FAILS
<input id="next_task" name="next_task" wire:click="hide" checked value="1" type="checkbox" value="" >
<label for="next_task">Create next task</label>
<x-input-label for="next_date" :value="__('Next task date')" class="mt-2"/>
<input type="date" id="next_date" name="next_date">
<x-input-error class="mt-2" :messages="$errors->get('next_date')" />
// next fields...
@endif
</div>
The livewire controller is:
class Nextavgtask extends Component
{
public $show, $hide = true, $status_types, $action_types, $whoisnext_types, $activity_types;
public function render()
{
return view('livewire.nextask');
}
public function show()
{
$this->show = true;
$this->hide = false;
}
public function hide()
{
$this->show = false;
$this->hide = true;
}
}
Please or to participate in this conversation.