laravel-form-builder icon indicating copy to clipboard operation
laravel-form-builder copied to clipboard

Disabling validation rules on removing a field

Open thedjdoorn opened this issue 7 years ago • 1 comments

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.

thedjdoorn avatar Aug 21 '17 14:08 thedjdoorn

At what moment do you remove the field, when sending it to view, or when doing validation in the controller method?

kristijanhusak avatar Nov 20 '17 14:11 kristijanhusak