views ajax form alter I have some slightly complicated ajax form logic that I'm struggling with.

I would like to replicate the following form conditions.

radio1 - always visible
option1
option2
option3

radio2 - only visible if option 2 and 3 are selected in radio1
option1
option2
option3

select3 - only visible if option 1 is selected in radio1
contents of select list to be controlled by on options in radio2

Problems

when radio2 is changed it still fires the ajax function 

when the form is submitted the select list uses the default option set rather than one that has been built from the selection radio2

Below is the code I have used following the ajax example from the examples module.

function uk_general_form_views_exposed_form_alter(&amp;$form, &amp;$form_state, $form_id) {
if($form['#id'] == 'views-exposed-form-documentation-search-page') {
if(!empty($form_state['values'])) {
  $form_state['input'] = array_merge($form_state['input'], $form_state['values']);      
}
$doc_type_options = $form['type']['#options'];    
$form['type'] = array(
  '#type' =&gt; 'radios',
  '#options' =&gt; $doc_type_options,
  '#title' =&gt; '',
);

$doc_line_options = $form['line']['#options'];
$line_selected = isset($form_state['values']['line']) ? $form_state['values']['line'] : key($doc_line_options);    
$form['line'] = array(
  '#type' =&gt; 'radios',
  '#options' =&gt; $doc_line_options,
  '#title' =&gt; '',
  '#ajax' =&gt; array(
    'callback' =&gt; 'uk_general_forms_documents_products',
    'wrapper' =&gt; 'products-dropdown-replace',
  ),      
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="type"]' =&gt; array(
        array('value' =&gt; '29'),
        array('value' =&gt; '31'),
        ),
      ),
    'disabled' =&gt; array(
      ':input[name="type"]' =&gt; array('value' =&gt; '30'),
      ),
    ),
  );
$form['title'] = array(
  '#type' =&gt; 'select',
  '#prefix' =&gt; '&lt;div id="products-dropdown-replace"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  '#options' =&gt; _get_products($line_selected),
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="type"]' =&gt; array('value' =&gt; '29'),
    ),
    'disabled' =&gt; array(
      ':input[name="type"]' =&gt; array(
        array('value' =&gt; '30'),
        array('value' =&gt; '31'),
      ),
    ),
  ),
);
}
}

function uk_general_forms_documents_products($form, $form_state){
  return $form['title'];
}

function _get_products($selected) {
  $product_query = new EntityFieldQuery;
  $product_query-&gt;entityCondition('entity_type', 'node')-&gt;entityCondition('bundle', 'product')-&gt;fieldCondition('field_line', 'tid', $selected)-&gt;propertyOrderBy('title', 'ASC');  
  $result = $product_query-&gt;execute();
  $product_nids = array_keys($result['node']);
  $products = entity_load('node', $product_nids);  
  $titles['All'] = '- Any -';
  foreach($products as $product) {
    $titles[$product-&gt;title] = $product-&gt;title;        
  }  
 return $titles;
}
i finally worked this one out, I strppied the form right back and removed all the states and got the ajax call working first. This was a bit of a hack as I had to access the $_GET variable directly and using the following line I was able to check whether or not the page had already been searched.

if(isset($_GET['line_2'])) {
  $line_2_selected = $_GET['line_2'];
}
else{
$line_2_selected = isset($form_state['values']['line_2']) ? $form_state['values']['line_2'] : key($doc_line2_options);
}


After this the problem was either having the ajax selectively removed ot depending on the values in the parent checkboxes. What I actually did was add the same list twice and then disable one or the other depending on the value in the first checkbox. Doing this greatly reduced the complexity of the states array.

$form['line'] = array(
  '#type' =&gt; 'radios',
  '#options' =&gt; $doc_line_options,
  '#default_value' =&gt; $line_selected,
  '#title' =&gt; '',
  '#prefix' =&gt; '&lt;div id="lines-dropdown-replace"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  '#states' =&gt; array(
    'enabled' =&gt; array(
      ':input[name="type"]' =&gt; array('value' =&gt; 31)
    ),
    'visible' =&gt; array(
      ':input[name="type"]' =&gt; array('value' =&gt; 31)
      ),
  ),
);

$form['line_2'] = array(
  '#type' =&gt; 'radios',
  '#options' =&gt; $doc_line2_options,
  '#default_value' =&gt; $line_2_selected,
  '#title' =&gt; '',
  '#prefix' =&gt; '&lt;div id="lines-dropdown-replace"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',      
  '#ajax' =&gt; array(
    'callback' =&gt; 'uk_general_forms_documents_products',
    'wrapper' =&gt; 'products-dropdown-replace',
    ),
  '#states' =&gt; array(        
    'enabled' =&gt; array(
      ':input[name="type"]' =&gt; array('value' =&gt; 29)
      ),
    'visible' =&gt; array(
      ':input[name="type"]' =&gt; array('value' =&gt; 29)
      ),
    )
  );


The previous ajax functions all worked as expected.