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

Skip to content

[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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
{{ block('choice_widget_options') }}
</optgroup>
{% else %}
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}{% if choice.disabled %} disabled="disabled"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
{% endif %}
{% endfor %}
{% endspaceless %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<?php echo $formHelper->block($form, 'choice_widget_options', array('choices' => $choice)) ?>
</optgroup>
<?php else: ?>
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($is_selected($choice->value, $value)): ?> selected="selected"<?php endif?>><?php echo $view->escape($translatorHelper->trans($choice->label, array(), $translation_domain)) ?></option>
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($is_selected($choice->value, $value)): ?> selected="selected"<?php endif?><?php if ($choice->disabled): ?> disabled="disabled"<?php endif?>><?php echo $view->escape($translatorHelper->trans($choice->label, array(), $translation_domain)) ?></option>
<?php endif ?>
<?php endforeach ?>
11 changes: 10 additions & 1 deletion src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,26 @@ class ChoiceView
*/
public $label;

/**
* Is choice disabled.
*
* @var Boolean
*/
public $disabled;

/**
* 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.
Copy link
Contributor

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

*/
public function __construct($data, $value, $label)
public function __construct($data, $value, $label, $disabled = false)
{
$this->data = $data;
$this->value = $value;
$this->label = $label;
$this->disabled = $disabled;
}
}