Ticket #367 (closed task: fixed)

Opened 3 years ago

Last modified 3 years ago

Fix some of the borderline inoperable ugliness of the validation system

Reported by: david Owned by: dominik
Priority: high Milestone: 0.11
Component: validation Version:
Severity: blocker Keywords:
Cc: Patch attached:

Description (last modified by david) (diff)

Right now, the validation system has some serious flaws:

  • It's often not possible to make a connection between errors and their fields
  • You cannot retrieve and modify validators at runtime (e.g. in registerValidators()), and therefor not add child validators to an existing one etc
  • You cannot get information about the status of validators or fields after validation, e.g. "did this isImageFileValidator report that field foo is an image or not?", which is very important to many people

Some suggestions:

  • Move all error related methods from Request to ValidatorManager
  • Make things simple
    • Allow more than one error message per field?
    • Method to retrieve all errors of a field
    • Method to retrieve all errors of a field and validator
    • Method to retrieve all errors of a validator
    • Method to retrieve all errors of a validator and field (with foo[] support)
    • Method to check if a field has any errors
    • Method to check if a field has errors set by a validator
    • Method to check if a validator has any errors
    • Method to check if a validator has any errors for a field (e.g. all foo[] fields)
  • Make things consistent
    • Is information, where feasible (e.g. severity), inherited correctly from parent validators?
    • What happens if a parent validator defines an error message, too?
      • How are these accessed? AndValidators? cannot be queried by field name directly? Do all children have that message in them, or is it just in the and validator itself? How do we do it?
    • What happens to the "default" error message (the one without a for attribute)? Should it be added if another error message was set? I think no, because for a minlength string validator, it would be stupid to see "Please enter a name", too, if the field has been filled in, but with too few characters.
  • Make things useful
    • Allow getting specific validators at runtime
      • Validator named "foo"
      • All childs of validator "foo"
      • All validators for field "blah"
    • Allow modifications to validators at runtime (i.e. in registerValidators())
      • Adding (also as "child of "foo")
      • Removing
      • Changing (Properties, Fields, Depends/Provides and such)

Attachments

Change History

Changed 3 years ago by david

  • description modified (diff)

Changed 3 years ago by david

  • description modified (diff)

All validators for field "blah"

Not gonna happen

Changed 3 years ago by dominik

  • status changed from new to assigned

The relations between validators and the errors looks like this now:

  +------------+           +------------+
  | Validator  |           | Error      |
  +------------+           +------------+
        | 1                n /\     | n  
        |                   _/      |    
        |                 _/        |    
        |               _/          |    
        |             _/            |    
        V 0-n       _/              V n  
  +------------+ 1_/       +------------+
  | Incident   |_/         | Field      |
  +------------+           +------------+

Changed 3 years ago by dominik

(In [1444]) BREAKING CHANGE! - Reworked the internal error handling in the validation. Now validators have multiple incidents (usually one per failed internal run [one validator internally runs multiple times when you give it a base and it has to validate more then one field that way). An incident can have multiple errors, which can span multiple fields. - Removed AgaviRequest::removeError (this a) doesn't work anymore and b) was a quite questionable thing to do in your code imho) - Adjusted error retrieval/setting methods in AgaviRequest? to work with the new system. (please note that the only(!) reliable way to check if the validation failed is AgaviRequest::hasErrors(), the other methods will return the errors with the notice severity too and getErrorNames and hasError will actually return the fields with severity none as well) - removed getRequest and reportError from validator containers - fixed operator validators not storing their name - added new result for not executed validators - renamed hasAllArgumentsSet to checkAllArgumentsSet - removed getAffectedFields completely (this currently makes the affects parameter of a validator useless) - fixed the isset validator when used with a base and when the field was empty - a whole lot of new methods for the validatorManager

refs #367

Changed 3 years ago by dominik

  • status changed from assigned to closed
  • resolution set to fixed

this has been fixed in [1444], [1446] and [1458]

Add/Change #367 (Fix some of the borderline inoperable ugliness of the validation system)

Author


E-mail address and user name can be saved in the Preferences.


Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.