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

Form implements InputFilterProviderInterface - validators fix #82

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Form implements InputFilterProviderInterface - validators fix #82

wants to merge 1 commit into from

Conversation

michalbundyra
Copy link
Member

When Form implements InputFilterProviderInterface and validators for an element are defined in method getInputFilterSpecification, only these validators should be added to the InputFilter of the Form for the element.
The same behavior should be for Fieldsets and it works fine. Basically, validators defined in getInputFilterSpecification should override default validators of the Element.

@megapixar
Copy link

Does this fix mean, that I have to copy all filters from method getInputSpecification of elements like (Email, Number) or my custom element and paste it to getInputFilterSpecification just to set field 'required' => false ???
Does it make sense?

@michalbundyra
Copy link
Member Author

@akrabat Could you have a look on it, please?

@froschdesign froschdesign mentioned this pull request Feb 23, 2017
@michalbundyra
Copy link
Member Author

@froschdesign @akrabat rebased

@akrabat
Copy link
Contributor

akrabat commented Feb 23, 2017

Is this a BC break?

@akrabat
Copy link
Contributor

akrabat commented Feb 23, 2017

i.e. if I add an email element and specify an additional validator that the length must be greater than 5, does this PR mean that the EmailAddress validator is no longer added?

@michalbundyra
Copy link
Member Author

michalbundyra commented Feb 23, 2017

@akrabat I've created an example here: https://gist.github.com/webimpress/e08e5a8928cbc3fec249fdc723705652

So, without my fix we have got:

NUMBER OF VALIDATORS:
field   form    fieldset
email   2       1
custom  2       1

and with my fix we have:

NUMBER OF VALIDATORS:
field   form    fieldset
email   1       1
custom  1       1

Basically there is something wrong. I've decided to do this way, so override default validators. In my application always I'm using fieldset and always when I get field from fieldset (from a form) validators specified in getInputFilterSpecification are only used.

Please note, I haven't changed any tests, so I haven't break (tested) functionality. IMHO if you implement form with InputFilterProviderInterface then you want specify input filter rules in the form, so only these should be used.

Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a BC break, as it's a break in expectations. As an example, the comments in #78 indicate that developers are expecting that InputProvider elements are merged with the related input from an InputFilterProvider fieldset. This allows them to alter the input (e.g., change the required flag, add additional validators and filters) without needing to provide a full specification for the element.

That said, I can also see how this would be an area rife for problems, and we should likely revisit for a v3 release.

@weierophinney weierophinney added this to the 3.0.0 milestone Apr 26, 2017
@weierophinney
Copy link
Member

This repository has been moved to laminas/laminas-form. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:

  • Squash all commits in your branch (git rebase -i origin/{branch})
  • Make a note of all changed files (`git diff --name-only origin/{branch}...HEAD
  • Run the laminas/laminas-migration tool on the code.
  • Clone laminas/laminas-form to another directory.
  • Copy the files from the second bullet point to the clone of laminas/laminas-form.
  • In your clone of laminas/laminas-form, commit the files, push to your fork, and open the new PR.
    We will be providing tooling via laminas/laminas-migration soon to help automate the process.

@michalbundyra
Copy link
Member Author

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at laminas/laminas-form#44.

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

Successfully merging this pull request may close these issues.

4 participants