-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add ability to disable choice in form #7510
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
* Creates a new ChoiceView. | ||
* | ||
* @param mixed $data The original choice. | ||
* @param string $value The view representation of the choice. | ||
* @param string $label The label displayed to humans. | ||
* @param string $disabled Is choice disabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a Boolean there
This should be supported in the PHP templates too, and should be tested |
May be an option // Array
$builder->add('category', 'entity', array('disabled_choices' => array($category));
// Closure
$ids = $this->getEmptyCategoryIds();
$disabledChoices = function($categories) use ($ids) {
return $categories->filter(function ($category) {
return in_array($category->value, $ids, true);
});
};
$builder->add('category', 'choice', array('disabled_choices' => $disabledChoices)); |
ping @bschussek |
Any news ? Or any other merged PR with this functionality ? |
Same here, any news? |
+1 |
1 similar comment
+1 |
Any news on this? I think this ticket could be closed with this? #3836 |
The implementation is fine, but missing a way to configure the "disabled" property, as @marcospassos pointed out. I think a nice API would be a "choice_attr" option which accepts a closure and receives each choice as argument: $form->add('tags', 'choice', array(
'choices' => // ...
'choice_attr' => function ($choice) {
if (/* ... */) {
return array('disabled' => true);
}
return array();
},
)); |
closely related to #4067 |
+1 This would be really useful when working with expanded choices (e.g. checkboxes). For example I am presently implementing a form which shows all possible facets for a search, as you filter the results some facets become unavailable - these need to be "disabled" but remain visible in the form. |
Since there's no more work continuing on this PR, I'm closing it. I added the feature request to #4067. |
Example: