Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form implements InputFilterProviderInterface - validators fix #44

Closed
michalbundyra opened this issue Jan 15, 2020 · 9 comments
Closed
Labels
BC Break Won't Fix This will not be worked on

Comments

@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.


Originally posted by @michalbundyra at zendframework/zend-form#82

@michalbundyra
Copy link
Member Author

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?


Originally posted by @megapixar at zendframework/zend-form#82 (comment)

@michalbundyra
Copy link
Member Author

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


Originally posted by @michalbundyra at zendframework/zend-form#82 (comment)

@michalbundyra
Copy link
Member Author

@froschdesign @akrabat rebased


Originally posted by @michalbundyra at zendframework/zend-form#82 (comment)

@michalbundyra
Copy link
Member Author

Is this a BC break?


Originally posted by @akrabat at zendframework/zend-form#82 (comment)

@michalbundyra
Copy link
Member Author

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?


Originally posted by @akrabat at zendframework/zend-form#82 (comment)

@michalbundyra
Copy link
Member Author

@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.


Originally posted by @michalbundyra at zendframework/zend-form#82 (comment)

@michalbundyra
Copy link
Member Author

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.

Originally posted by @weierophinney at zendframework/zend-form#82 (comment)

@Slamdunk
Copy link
Contributor

Slamdunk commented May 28, 2021

@froschdesign I understand the motivation for zendframework/zend-form#82 but I do not agree that's a good solution.
Most common usage I know consists of implementing getInputFilterSpecification just to add 'required' => true and StringTrim filter, it would be tedious and error prone to repeat default validators just for a 'required' => true.

So I'm inclined to close this as Won't fix; WDYT?

@froschdesign
Copy link
Member

So I'm inclined to close this as Won't fix; WDYT?

Go for it. The way is always open to create a new issue report.

@Slamdunk Slamdunk added the Won't Fix This will not be worked on label May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BC Break Won't Fix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants