Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Removing an element from a form will keep the inputfilter alive #2839

Closed
Damu112 opened this issue Oct 26, 2012 · 5 comments
Closed

Removing an element from a form will keep the inputfilter alive #2839

Damu112 opened this issue Oct 26, 2012 · 5 comments

Comments

@Damu112
Copy link

Damu112 commented Oct 26, 2012

Steps to reproduce:

  • Create a form with at least two elements
  • Remove one element during runtime using $form->remove('name');
  • Render, submit and validate the form

Result:

Validation will fail because the inputfilter (which is required by default) still remains in the form. However, as the element itself doesn't exist anylonger, no message will be generated ($form->getMessages(); will be empty in case of no other valdiation errors).

Workaround:

Also remove the inputfilter:

$form->remove('name');
$form->getInputFilter()->remove('name');
@blanchonvincent
Copy link
Contributor

👍
@bakura10, input filter must be valid only with the elements in the forms.

@bakura10
Copy link
Contributor

Use validation groups on forms for that.

@blanchonvincent
Copy link
Contributor

@bakura10 Yeah agree, but you think the match must not have to exist ?
Validation group is used to limitied the validation (like an update), not for a normal use case, no ?

@Damu112
Copy link
Author

Damu112 commented Oct 26, 2012

Well, does it even make sense to keep the input definition in the form when the element is removed? No element -> no data -> no input required.

Or do I miss something here?

@weierophinney
Copy link
Member

The form and the input filter are separate objects. To keep them informed of the state of one another requires further coupling. This is precisely why validation groups were created -- if you're changing the set of elements in the form, then you should also set the validation group so that it only includes what you plan to validate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants