Bug #33300
Validators should allow empty values
Status: | Resolved | Start date: | 2012-01-18 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | Bastian Waidelich | % Done: | 100% |
|
Category: | Validation | |||
Target version: | TYPO3 Flow Base Distribution - 1.1 | |||
PHP Version: | Complexity: | |||
Has patch: | No | Affected Flow version: | Git master |
Description
Currently most of the provided validators do not accept empty values. This makes it impossible to have an optional email address for example (without using the disjunction validator).
If an email is required one should add two validation rules, NotEmpty and EmailAddress to the respective property.
Related issues
Associated revisions
[!!!][BUGFIX] Validators should allow empty values
Currently most of the provided validators do not accept empty
values.
This makes it impossible to have an optional email address
property for example (without using the disjunction validator).
This change adjusts all Validators to consider empty values
(NULL or an empty string) valid.
This is a breaking change if you expected the previous behavior.
In order to make a property required you now need to add the
NotEmptyValidator explicitly!
E.g.:
previously:
/**
* @FLOW3\Validate(type="EmailAddress")
*/
protected $propertyToValidate;
Now:
/**
* @FLOW3\Validate(type="NotEmpty")
* @FLOW3\Validate(type="EmailAddress")
*/
protected $propertyToValidate;
Change-Id: I3a2b6df09573939d430c2aa28ef5d8919815b955
Fixes: #33300
Releases: 1.1
History
#1 Updated by Gerrit Code Review over 3 years ago
- Status changed from Accepted to Under Review
Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/8691
#2 Updated by Felix Oertel over 3 years ago
I went into the same problems two weeks ago and tried to come up with a good solution.
I would highly prefer to enable proper disjunction usage over breaking the current behavior. Validating "EmailAddress" in my eyes means "EmailAddress" and not "EmtpyString" (and thus, no "EmailAddress").
Allowing usage of OR (disjunction validator) would solve our problems much better and non-breaking I think.
Ps: I came up with some (EmailAddress OR Empty) syntax, but don't know if this is really the way to go.
#3 Updated by Bastian Waidelich over 3 years ago
Felix Oertel wrote:
I would highly prefer to enable proper disjunction usage over breaking the current behavior.
I thought about this quite a while and I'm pretty sure the new behavior makes much more sense.
E.g. when working with Forms (which is the most common scenario for Validators) you want to differentiate whether a field is required (the label gets an asterisk for example) and/or whether it should be a valid email address if specified.
I agree, that you would probably add NotEmpty as well in most cases, but the behavior is at least consistent. BTW: Some validation engines I looked at handle it the same (only they call it "required" and not "NotEmpty" which is maybe a better choice)
#4 Updated by Bastian Waidelich over 3 years ago
Felix Oertel wrote:
Ps: I came up with some (EmailAddress OR Empty) syntax, but don't know if this is
really the way to go.
What syntax did you come up with by the way?
#5 Updated by Bastian Waidelich over 3 years ago
Bastian Waidelich wrote:
I thought about this quite a while and I'm pretty sure the new behavior makes much more sense.
I (we) thought about it some more and now I'm not so sure anymore ;)
At least in domain models an optional email address is rather an edge case. So if we found a nice way to specify validation rules as logical or this would be a good solution too.
Something like
@FLOW3\ValidateFirst({type="NotEmpty"}, {type="StringLength", options={maximum=100}})
only nicer.. ;)
#6 Updated by Felix Oertel over 3 years ago
Yeah, this is exactly, what I talked about in the first place. ;-)
I did some testing implementation (in extbase of course) and found, that specifying validators in the disjunction validator's options were much too complex and error prone. So I thought that probably a simple but new syntax would be good
@validate $email (NotEmpty OR EmailAddress)
or
@validate $email ((Empty OR StringLength(maximum=100)) OR EmailAddress)
- look if the first char is "("
- look for "AND" or "OR"
- trigger parsing of the seperate validators again and join in con- or disjunction
This would even allow to nest validations as the first char of the first parsed/nested expression can be a "(" again.
As long as it's forbidden to use AND and OR in the same nesting level, it should be fairly simple to implement.
#7 Updated by Gerrit Code Review over 3 years ago
Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/8691
#8 Updated by Gerrit Code Review over 3 years ago
Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/8691
#9 Updated by Gerrit Code Review over 3 years ago
Patch set 4 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/8691
#10 Updated by Bastian Waidelich over 3 years ago
As discussed in todays daily scrum meeting we'll change the validators as suggested in the first changeset (with some refactoring to reduce the amount of code duplication) because it is the expected behavior.
Besides the NotEmpty validator should be renamed to "Required" (see #33537)
#11 Updated by Gerrit Code Review over 3 years ago
Patch set 5 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/8691
#12 Updated by Bastian Waidelich over 3 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 9b627954f289d793b808db2ac19edc6a04c25426.
#13 Updated by Simon Schaufelberger over 3 years ago
can this be backported (is this the correct word?) for TYPO3 as well?