#Feature Auto-refresh a form
Auto-refresh a form
You can automatically send an ajax request to update your form when an input/select change, just add the data attribute "data-refreshonchange":
<select name="category" data-refreshonchange="true">
<option value="transport">Transport</option>
<option value="structure">Stucture</option>
</select>
Then in your controller's action:
if ($request->query->get('novalidate', false) === false) {
if ($form->isValid()) {
// form is valid
} else {
// avoid to display errors when novalidate
$form = $formFactory->createForm();
$form->setData($user);
}
}
For some reason, you would not refresh some parts of your form (for example an input type="file"). Then, add the data attribute 'data-ignoreonchange="$some_unique_id"'.