-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Form] New form BooleanType class #27185
Comments
Hi, thanks for finding the Gist useful :) About the request, I don't think it should be added into core because the current implementation is limited to API only and is not intended to be displayed on a browser. For me, FOSRestBundle (issue : FriendsOfSymfony/FOSRestBundle#1224 / PR : FriendsOfSymfony/FOSRestBundle#1312) is the best place to have this form type (my library is a temporary solution until the PR on FOSRestBundle is finished) But, to quote webmozart (FriendsOfSymfony/FOSRestBundle#1312 (comment)):
|
I think what OP suggests is to have just new form type which is just preconfigured choicetype with yes/no choices. Such form type is really common in projects. We use following and it works fine, even in non-API context. class YesNoRadioType extends AbstractType
{
const CHOICES = ['YES' => true, 'NO' => false];
public function getParent()
{
return ChoiceType::class;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'expanded' => true,
'choices' => self::CHOICES,
]);
}
} |
Yes, I agree with @ostrolucky and find useful the @emulienfou’s proposal. |
Does anyone of you want to work on a PR implementing this type? |
Would it be better if BooleanType parent is ChoiceType ? |
In the solution proposed in #27185 (comment) the parent type is |
Btw my opinion on the matter is this issue cannot be satisfied in generic, non-opinionated way. Some people will want it to be checkbox instead of radios, some dropdown, other people something else than yes/no labels. Having own type for this is few lines of codes and guarantees it's the way user wants. Trying to customize such booleanType that would be shipped officially doesn't save much. So in the end letting user create whatever choicetype child as is the case now might be better. |
@ostrolucky I don't think that really is an issue. This can be customised through the options inherited from the |
So can ChoiceType. User isn't saving much. |
I've the same opinion as @ostrolucky about this proposal, this custom type is very simple to be created by anyone. Also extending it from |
Let's close then. |
I think it would be great/easier to have a form BooleanType, instead of using the ChoiceType with yes/no values!
What do you think?
The text was updated successfully, but these errors were encountered: