Skip to content

Disable radio button not working #4136

Chintanvpatel opened this Issue Mar 28, 2013 · 2 comments

2 participants


Adding form element in form using
'type' => 'Zend\Form\Element\Radio',
'name' => 'gender',
'options' => array(
'label' => 'What is your gender ?',
'value_options' => array(
'0' => 'Female',
'1' => 'Male',

On view
echo $this->formRow($form->get('gender'));

When i try to disable it from controller using below code, It's not working.
$form->get('gender')->setAttribute('disabled', 'true');

grizzm0 commented Mar 28, 2013

I don't have time to debug it and create a PR atm. But atleast I tracked it down to these rows.

$options simply contain a key => value pair of the value_options key.

array(2) {
  [0] => string(6) "Female"
  [1] => string(4) "Male"

Therefore the isset($optionSpec['disabled']) will always return false and $disabled will never be set.
This seems to do the trick.

            if (is_scalar($optionSpec)) {
                $optionSpec = array(
                    'label' => $optionSpec,
                    'value' => $key

                if (isset($inputAttributes['disabled'])) {
                    $disabled = $inputAttributes['disabled'];
grizzm0 commented Mar 28, 2013

Oh, I see what happens. :o $disabled is set to false at the top of the foreach, it then checks to see if $optionsSpec['diabled'] is set. It then sets $inputAttributes['disabled'] = $disabled which is false if $optionsSpec['disabled'] isn't set. I'm not sure who coded this and how it's intended to work. But the code below works.

            $value           = '';
            $label           = '';
            $selected        = false;
            $disabled        = isset($attributes['disabled']) ? true : false;
            $inputAttributes = $attributes;
            $labelAttributes = $globalLabelAttributes;
@weierophinney weierophinney added a commit that closed this issue Apr 15, 2013
@weierophinney weierophinney Merge branch 'hotfix/4180'
Close #4180
Fixes #4136
@ghost Unknown pushed a commit that referenced this issue Jul 14, 2013
@weierophinney weierophinney Merge branch 'hotfix/4180'
Close #4180
Fixes #4136
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.