laravel-form-builder
laravel-form-builder copied to clipboard
Disabling validation rules on removing a field
Currently, when a form field has rules, those rules remain active when the field is removed. Can this be fixed and/or is there a workaround?
Example: PersonForm.php
public function buildForm()
{
$this
->add('name', 'text', [
'rules' => 'required'
])
->add('age', 'text',[
'rules' => 'required'
]);
}
PersonController.php
//...
$form->remove('name');
//...
If the form is submitted it will be sent back because even though it has been removed, the name field is still required.
At what moment do you remove the field, when sending it to view, or when doing validation in the controller method?