-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[DX][Form] Change default value of "required" option to false #12018
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
Conversation
👍 |
This would be great! +1 |
What do you think about renaming |
@shoomyth Not much. As you see above, fields without the |
👍 |
Yeah, required false should be default, I've had to force it in all my projects. As an aside, it is absurd that the choice options show a (not applicable) choice by default when required is false. I want the user to pick the choices I give, and if I set required false, I'd like them to be able to skip the question without having framework generated options. |
+1 |
1 similar comment
👍 |
I think, its very difficult to make a default guess, without any information. So for me the only answer would be, making it configurable. Perharps a DefaultGuesser might be a good idea. |
Big 👍 from me from a feature-standpoint. This is one of my least favorite moments in a training - when I explain that all their fields have a "required" HTML5 attribute unless they explicitly say So my only worry would be BC breaks and I'm thinking of the client-side variety as you eluded to. It seems minor, but if I was kind of depending on that |
@webmozart I think you somewhere also suggested an alternative solution: to add the NotNull constraint automatically when the field is required. Would this be an option? See #3822 |
I'm not sure if +1 or -1. From a UX I would say +1, as it's so annoying the fact that you have to manually set required to false on checkboxes, but this is the only case I usually have to. The only issue I see is that for Doctrine ORM the default nullable option is set to false and that means you would have different default values for a similar concept. |
Well I would say @Gladhon suggestion is a good idea, cause without we get many days working on old projects without a benefit. |
@weaverryan Remember that all fields with a @Tobion Yes. That's a different issue though IMO, since it requires merging of the model and form constraints. I'm not even sure whether it's doable. @stefanosala For properties mapped in Doctrine, the "required" option is guessed based on the value of "nullable". So fields for properties with "nullable" set to false will still be required. |
@webmozart you forget that the guessing is only done when no type is given for a field. And from my experience most of the time developers explicitly set the field type. So the change will definitely have impact on many projects. But I'm still 👍 to change the default |
@webmozart IMO, this should indeed wait until the guessing is improved to be usable even when specifying the type. Otherwise, it is a big BC break (if we were only loosing the client-side validation on some fields unless re-adding the option explicitly, it would be fine, as you should never trust the client-side validation anyway, but as you said, this impacts the way some forms are built too) |
@stof Alright, let's do this for 2.7 then. |
@webmozart Is it still true that the guessing only happens if you don't specify a field type (i.e. you allow the field type itself - like Anyways, I'm really excited to have this improved whenever we can. But I do think there are some BC breaks here on the client side. But if we had a configuration option to toggle between the old and new default value, then maybe it's a non-issue. |
@weaverryan That's still the case. That's why we need to fix #7868 before merging this. |
ref #7181 |
👍 I'm in favor of this change. It was very weird to set required to false on field you don't want HTML5 required attribute. A lot of my past hotfix was targeting this kind of thing. |
I am too, in favor of this change. But wouldn't this affect forms with children? According to https://github.com/symfony/symfony/blob/2.5/src/Symfony/Component/Form/FormInterface.php#L202 all the children's form fields would be forced non-required (even if you set them to required) if the parent is not required. Maybe this a whole other problem but setting |
@webmozart |
Why not have an option at the |
@jxmallett Even if this would help to prevent a BC it doesn't seem right and a small bloat of the formBuilder interface. I still opt for the main request of webmozart which makes so more sense that how required is currently set if no validation constraint was configured (i.e., the default behavior). |
What about this one @webmozart? |
Closing as there is no more activity here. If anyone wants to take over, that would be great of course. |
This is an attempt to set the default value of the "required" option of all form types to false. Let's list the usage scenarios that we have at the moment:
NotNull
/NotBlank
required
required
NotNull
/NotBlank
true
required
true
required
NotNull
/NotBlank
false
false
By setting the default of the "required" option to false, only one case changes:
This obviously makes more sense than validating a value on the client side that isn't validated on the server side.
Consequences
required
attribute anymoreNotNull
/NotBlank
constraint. In that case, "required" should be set to true by defaultThe only major consequence I see is if people don't use the Validator component for validation, but some custom mechanism. In that case, we can't detect whether a field is validated or not, so all fields without explicit "required" option loose their HTML attribute. However:
So even there, I don't think the consequences are very serious.
What do you think?
Todos (in case a majority votes for this PR)
NotBlank
/NotNull
is given