Open
Description
Given I have a form with one field which should reset after submit, the field is not updated (emptied in my case) after hitting the enter button. By clicking the submit button, it works.
Any chance to solve this without writing JavaScript?
Thanks for any help!
#[AsLiveComponent]
class Search extends AbstractController
{
use DefaultActionTrait;
use ComponentToolsTrait;
use ComponentWithFormTrait;
#[LiveAction]
public function submit(): void
{
$this->submitForm();
$this->resetForm();
}
protected function instantiateForm(): FormInterface
{
// we can extend AbstractController to get the normal shortcuts
return $this->createForm(DeviceBarcodeType::class, ['barcode' => '']);
}
private function getDataModelValue(): ?string
{
return 'norender|*';
}
}
<div>
{{ form_start(form, {
attr: {
'data-action': 'live#action:prevent',
'data-live-action-param': 'submit',
}
}) }}
{{ form_row(form.barcode) }}
<button
type="submit"
>Submit
</button>
{{ form_end(form) }}
</div>