Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[3.0] [Validator] Remove Blank/NotBlank constraint #12300

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

Closed
webmozart opened this issue Oct 23, 2014 · 18 comments
Closed

[3.0] [Validator] Remove Blank/NotBlank constraint #12300

webmozart opened this issue Oct 23, 2014 · 18 comments

Comments

@webmozart
Copy link
Contributor

I think that the Blank/NotBlank constraints should be removed in 3.0. It's not quite clear what the constraints do (see #9961) and I guess we're better off if we just removed it. People can use other, more specific constraints instead, such as True, Length, Count etc.

@Tobion
Copy link
Contributor

Tobion commented Oct 23, 2014

So for required fields, devs have to add the NotNull constraint, do they? I guess that's the common problem that people don't know how to validate optional/required fields. And using NotBlank seems more natural than NotNull.
And also the confusion whether an optional value is '' or null, see #11956. This then also influences whether NotNull actually works for required fields.

@webmozart
Copy link
Contributor Author

So for required fields, devs have to add the NotNull constraint, do they?

Exactly. As I said, they can use other means (such as Type and Length validation) to validate a value more specifically.

@Tobion
Copy link
Contributor

Tobion commented Oct 23, 2014

But I think there is an inconsistency in this idea: One the one hand you say, empty fields are represented as null, so we need to use the NotNull constraint to validate required fields. On the other hand constraints still allow empty strings '' as described in #11956 although the only purpose is to allow optional fields. So if NotNull is the correct approach, then the constraints should also stop ignoring empty strings. But you closed this issue.

@webmozart
Copy link
Contributor Author

@Tobion You are completely right. Obviously we can't do this without breaking BC, so this is postponed to 3.0.

@stof
Copy link
Member

stof commented Oct 23, 2014

Exactly. As I said, they can use other means (such as Type and Length validation) to validate a value more specifically.

This would first require to stop ignoring empty strings in other validators, considering only null as a valid value to allow optional one

@webmozart webmozart changed the title [Validator] Deprecate NotBlank constraint [3.0] [Validator] Deprecate NotBlank constraint Oct 23, 2014
@stof stof added this to the 3.0 milestone Oct 23, 2014
@webmozart
Copy link
Contributor Author

@stof ;)

@Tobion
Copy link
Contributor

Tobion commented Oct 24, 2014

I just realize the nonsense of Blank vs NotBlank: false is invalid in both cases. lol
This means, false is "not blank" according to the BlankValidator and it is "blank" according to the NotBlankValidator.

@Tobion
Copy link
Contributor

Tobion commented Oct 24, 2014

@webmozart so when deprecating NotBlank, shouldn't Blank be deprecated as well?

@Tobion
Copy link
Contributor

Tobion commented Oct 24, 2014

Also the current issue description makes no sense. If we want to deprecate these constraints, then it must be done before 3.0. So the milestone is wrong.

@stof
Copy link
Member

stof commented Oct 24, 2014

The issue is that we cannot deprecate things without providing a replacement for the feature. and the new way cannot be built without BC break, so it cannot be built before 3.0. There is no way to deprecate it in 2.x for removal in 3.0

@webmozart webmozart changed the title [3.0] [Validator] Deprecate NotBlank constraint [3.0] [Validator] Remove Blank/NotBlank constraint Oct 24, 2014
@Remper
Copy link

Remper commented Oct 28, 2014

NotBlank should be deprecated. It's behavior is weird (as mentioned — false is invalid) and doesn't even conform to documentation where it is explicitly said that the value should be not equal to a blank string and also not equal to null.

@Remper
Copy link

Remper commented Oct 28, 2014

This commit actually broke everything: 639513a

@webdevilopers
Copy link

👍

@TomasVotruba
Copy link
Contributor

3.0 is already here.
What's current state of this? What would be the suggested replacement?

@webmozart
Copy link
Contributor Author

@TomasVotruba The problem is, as @stof said, that we can only deprecate these constraints if we remove the '' !== $value checks from all other constraints validators. Otherwise empty strings will be ignored by all validators.

Any other solutions or can we only do this as part of the 4.0 release?

@TomasVotruba
Copy link
Contributor

@webmozart Ok, that sound clear to me. Can prepare PR if this gets accepted.

@webmozart webmozart modified the milestones: 4.0, 3.0 Mar 4, 2016
@fabpot fabpot removed this from the 4.0 milestone Oct 18, 2016
@HeahDude
Copy link
Contributor

HeahDude commented Jul 30, 2017

I'm 👎 here in the way it is described, what we should do is:

  • document that false is invalid with Blank as for empty string and null,
  • better document difference between NotBlank and NotNull (the last one having to be used for boolean types)
  • deprecated invalid behavior for invalid state of false with Blank and NotBlank,
  • rename Blank and NotBlank to Empty and NotEmpty that would better reflect what it does mimicking PHP wording and behavior.

@xabbuh
Copy link
Member

xabbuh commented Sep 24, 2018

Let's close here in favour of #27876.

@xabbuh xabbuh closed this as completed Sep 24, 2018
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

10 participants