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

CMS 6 - changes to validators #10908

Closed
6 of 8 tasks
GuySartorelli opened this issue Aug 7, 2023 · 7 comments
Closed
6 of 8 tasks

CMS 6 - changes to validators #10908

GuySartorelli opened this issue Aug 7, 2023 · 7 comments

Comments

@GuySartorelli
Copy link
Member

GuySartorelli commented Aug 7, 2023

Follow up from #10907

Acceptance criteria

  • Rename FieldsValidator to FormFieldsValidator
  • RequiredFields should be renamed RequiredFieldsValidator to match the naming convention of other validators
  • Anywhere that just adds RequiredFields to a form should instead add CompositeValidator with both a FormFieldsValidator and (if necessary) RequiredFieldsValidator validator
    • Form::__construct() and SilverStripe\AssetAdmin\Forms\RemoteFileFormFactory::getForm() should explicitly exclude the RequiredFieldsValidator validator
  • FieldsValidator is removed
  • Form loops its form fields and calls validate on each of them
  • RequiredFieldsValidator should not call the validate() method on form fields, as that is the responsibility of the FormFieldsValidator.
  • Anywhere that previously added RequiredFields to a form just to get FormField validation to work no longer adds a validator
  • RequiredFieldsValidator can be configured to not consider whitespace only a value
    • RequiredFieldsValidator should be configurable to consider whitespace only values to not constitute the presence of a value
    • This should be configurable globally via YAML, and configurable for individual RequiredFieldsValidator instances via a new setter method.
    • It should be false by default e.g. mimic existing behaviour

Note about PRs

I've basically treated this like 3 separate issues and split the PRs

  • Allow whitespace changes
  • Rename classes
  • Call form field validate with form

CMS 5 PRs - allow whitespace only

CMS 5 PRs - rename classes

After merging all the above reassign to Steve to merge-up and rebase

Kitchen sink CI CM6 - rename classes

^ Unit test failure is existing

CMS 6 PRs - rename classes

Kitchen sink CI - call form field validate within form

^ Unit test failure is existing

CMS 6 PRs - call form field validate within form

@GuySartorelli GuySartorelli added this to the Silverstripe CMS 6 milestone Aug 7, 2023
@emteknetnz emteknetnz self-assigned this Sep 19, 2024
@emteknetnz emteknetnz assigned emteknetnz and unassigned emteknetnz Sep 29, 2024
@emteknetnz
Copy link
Member

emteknetnz commented Dec 3, 2024

@GuySartorelli Having a second look at these ACs it seems like they may cause a fair bit of upgrade pain as RequiredFields is a very commonly used class, and it's very likely that projects will forgot to "upgrade" them to be CompositeValidators that includes both a FieldsValidator and a RequiredFields, and now field validation will silently stop working

Even when they do remember to add it, it honestly sounds like really annoying boilerplate. People will wonder why they need to add a FieldsValidator since that should really just be there by default

I'm keen not to go with the original solution, I can think of a few alternative solutions instead:

Option A

  • Do nothing, or something minimal such as make RequiredFields extend FieldsValidator

Option B

  • Update the logic in Form so that no matter whatever Form::setValidator() is called with, when calling Form::getValidator() you always end up with a CompositeValidator with a FieldsValidator along with what the argument passed to setValidator() was if it wasn't a CompositeValidator or a FieldsValidator

Option C

  • Set the Form validator to a CompositeValidator with a FieldsValidator in Form::__construct()
  • Remove setValidator() and getValidator()
  • Add addValidator() which adds to the Forms CompositeValidator()
  • Add setCompositeValidator() and getCompositeValidator()

Option D

  • Get rid of FieldsValidator
  • Move it logic to Form::validate() to happen before calling the equivalent of $this->getValidator()->validate()

My recommendation is Option D as it seems like it should have always been doing this - can you think of any reason to not do this?

@GuySartorelli
Copy link
Member Author

D sounds fine.

@GuySartorelli
Copy link
Member Author

@emteknetnz It's not clear why this is assigned to me - there's no PRs that aren't in draft.

@emteknetnz
Copy link
Member

Sorry forgot to mark PRs as ready for review

@GuySartorelli
Copy link
Member Author

PRs merged. Reassigning to Steve for the next round

@emteknetnz
Copy link
Member

No more rounds, we're done :-)

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

No branches or pull requests

2 participants