Score:0

How to clear selected values from multiple select field

in flag

I have a form with a multiple select field where a user can select several values in it

$form['export_type_section']['export_type']  = array(
  '#title' => t('Export types'),
  '#type' => 'select',
  '#multiple' => TRUE,
  '#size' => 10, 
  '#options' => $options,
  '#ajax' => array(
    'event' => 'change',
    'callback' => 'test_export_form_export_type_ajax_callback',
  ), 
);

I have another field in the form

$form['document_type'] = array(
  '#type' => 'select',
  '#options' => array(0 => t('All Types'), 1 => t('Test1'), 2 => t('Test2'), 3 => t('Test3')),
  '#title' => 'Document Types',
  '#default' => 0,
  '#ajax' => array(
    'event' => 'change',
    'callback' => 'test_export_form_document_type_ajax_callback',
  ),
);

I am trying to figure out how to reset the export_type field when the document_type is changed. I would like to clear the selected values so that the user can reselect what is needed whenever the document_type changes. I tried several formats in the test_export_form_document_type_ajax_callback but none worked.

Anybody knows how to do it?

Kevin avatar
in flag
Did you try #states?
angela83 avatar
in flag
can you give me an example of how to clear the selected multiple values using #states?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.