Change the disabled status of a form element via Ajax I have a form built with the Form API. I have a field which is, at first, disabled. I want to change the status of that field to enabled when the user selects another contiguous field.

I have a working example of changing the callback URL of Ajax complete of that field, so the form is making a kind of OnChange and working well, but for some reason I am not able to change the disabled status.

Code. Here the 2 elements, first brand and next the model, which is disabled at the beginning.

 $form['brand'] = array(
'#type' =&gt; 'select',
'#title' =&gt; t('Brand'),
'#options' =&gt; $brands,
'#default_value' =&gt; $brand,
'#ajax' =&gt; array(
    'callback' =&gt; 'hook_models_update',
    'wrapper' =&gt; 'models_wrapper',
    'progress' =&gt; array(
        'message' =&gt; '',
        'type' =&gt; 'throbber',
    ),
),
);

 $form['model'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Model'),
  //    '#description' =&gt; 'Please note available models change based on the brand selected.',
'#required' =&gt; FALSE,
'#autocomplete_path' =&gt; 'providers/autocomplete/' . $brand,
'#attributes' =&gt; array("placeholder" =&gt; t('Model')),
'#prefix' =&gt; '&lt;div id="models_wrapper"&gt;',
'#suffix' =&gt; '&lt;/div&gt;',
'#disabled' =&gt; TRUE,
);


Now the code for the "onChange" behaviour, which is a "throbber" called hook_models_update:

function hook_models_update($form, &amp;$form_state) {
    unset($form_state['input']['model'], $form_state['values']['model']);
    $brand = $form_state['values']['brand'];
    $form['model']['#autocomplete_path'] = 'providers/autocomplete/' . $brand;
     $form['model']['#enabled'] = TRUE;
    // $form['model']["#disabled'] = FALSE
    return form_builder($form['#id'], $form['model'], $form_state);
} // function


I have tried with #enabled = TRUE and with #disabled = FALSE, with no successs.
I found the solution here:

Enable DropDown using Ajax Call

The code finally gets this:

     function hook_models_update($form, &amp;$form_state) {
         unset($form_state['input']['model'], $form_state['values']['model']);
         $brand = $form_state['values']['brand'];
         $form['model']['#autocomplete_path'] = 'providers/autocomplete/' . $brand;
         unset($form['model']["#attributes"]['disabled']);
         $form['model']['#disabled'] = FALSE;
         return form_builder($form['#id'], $form['model'], $form_state);
} // function


The trick lies in these two lines:

     unset($form['model']["#attributes"]['disabled']);
     $form['model']['#disabled'] = FALSE;


Apparently, there has to be an unset and not of #disabled, but #attributes - disabled. Why this is so convoluted is beyong my comprehension.