I am creating a multiple selection element using a fixed function called by AJAX and in the form reload. Even though the function is the same, the behavior is different.
& # 39;& # 39 ;,
& # 39; # suffix & # 39; => & # 39;
& # 39 ;,
);
$ form['form_wrapper']['properties'] = array (
& # 39; # prefix & # 39; => & # 39;Filter by sequence properties
& # 39 ;,
& # 39; # suffix & # 39; => & # 39;
& # 39 ;, //
& # 39 ;,
);
// Location of the sample collection
// drupal_set_message (print_r ($ location_li2), true); // $ location_li2 is not read correctly
$ country_li = array ();
$ state_li = array ("" => "");
foreach ($ location_li2 as $ location_li) {
$ country_li[$location_li[0]]= $ location_li[0];
yes (isset ($ _ POST['ddl1b']) && en_array ($ location_li[0], $ _POST['ddl1b']) && sizeof ($ location_li)> 1) {
foreach ($ location_li[1] like $ state) {
$ state_li[$location_li[0]. & # 39;: & # 39; $ state]= exploit (& # 39; | & # 39 ;, $ state)[0]; // include the country in the value of the state
}
}
}
$ form['#state_li'] = $ state_li;
$ form['form_wrapper']['properties']['collection_location']['title_wrapper'] = array (
& # 39; # prefix & # 39; => & # 39;Location of the sample collection | & # 39 ;,
& # 39; # suffix & # 39; => & # 39; |
& # 39 ;,
);
$ form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl1b'] = array (
& # 39; # prefix & # 39; => & # 39;& # 39 ;, // width: 49% "> & # 39 ;,
& # 39; # suffix & # 39; => & # 39;
& # 39 ;,
& # 39; # type & # 39; => & # 39; select & # 39 ;,
& # 39; # # multiple & # 39; => TRUE,
& # 39; # options & # 39; => $ country_li,
& # 39; # id & # 39; => & # 39; ddl1b & # 39 ;,
# # Attributes & # 39; => array (
& # 39; autocomplete & # 39; => & # 39; off & # 39 ;,
// & # 39; onchange & # 39; => & # 39; & # 39 ;,
)
& # 39; # ajax & # 39; => array (
& # 39; callback & # 39; => & # 39; add_state_select & # 39 ;,
& # 39; wrapper & # 39; => & # 39; ddl2b_wrapper & # 39 ;,
& # 39; progress & # 39; => array (& # 39; type & # 39; => & # 39; none & # 39;),
)
);
$ form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper'] = array (
& # 39; # prefix & # 39; => & # 39;& # 39 ;,
& # 39; # suffix & # 39; => & # 39;
& # 39 ;,
);
$ form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper'] = add_state_select ($ form, $ form_state);
$ form['form_wrapper']['table_button'] = array (
& # 39; # type & # 39; => & # 39; submit & # 39 ;,
& # 39; # value & # 39; => & # 39; Send & # 39 ;,
& # 39; # submit & # 39; => array (& # 39; enable_table & # 39;),
& # 39; # ajax & # 39; => array (
& # 39; callback & # 39; => & # 39; rebuild_form & # 39 ;,
& # 39; wrapper & # 39; => & # 39; form_wrapper & # 39 ;,
)
);
if (! empty ($ form_state['table'])) {
$ form['form_wrapper']['raw_html'] = array (
& # 39; # type & # 39; => & # 39; markup & # 39 ;,
& # 39; # markup & # 39; => & # 39;
PROOF! & # 39 ;,
);
}
returns $ form;
}
function rebuild_form ($ form, $ form_state) {
return $ form['form_wrapper'];
}
the enable_table ($ form, & $ form_state) {function
$ form_state['table'] = TRUE;
$ form_state['rebuild'] = TRUE;
}
function add_state_select ($ form, & $ form_state) {
// drupal_set_message (& # 39; triggeredst_state_select () & # 39;);
$ state_li = $ form['#state_li'];
$ form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper'] = array (
& # 39; # prefix & # 39; => & # 39;& # 39 ;,
& # 39; # suffix & # 39; => & # 39;
& # 39 ;,
);
if (sizeof ($ state_li)> 1) {
// drupal_set_message (& # 39; build conditional enabled & # 39;);
$ form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper']['ddl2b'] = array (
& # 39; # type & # 39; => & # 39; select & # 39 ;,
& # 39; # # multiple & # 39; => TRUE,
& # 39; # options & # 39; => $ state_li,
& # 39; # id & # 39; => & # 39; ddl2b & # 39 ;,
# # Attributes & # 39; => array (
& # 39; autocomplete & # 39; => & # 39; off & # 39 ;,
// & # 39; multiple & # 39; => & # 39; true & # 39 ;,
)
);
}
return $ form['form_wrapper']['properties']['collection_location']['title_wrapper']['ddl2b_wrapper'];
}
After interacting with the first drop-down menu (ddl1b, it contains country information), a single selection element (ddl2b) is produced. The form does not recognize & # 39; # # multiple & # 39; => TRUE
as a valid value The selection element can still be set to multiple using attributes, but the selections will no longer be recognized by $ form_state and will be lost in the reconstruction.

When the second selection element is created in the reconstruction of the page, it is correctly configured to accept multiple selections. The element has an expected behavior ($ form_state works, the selected elements remain in the reconstruction).

This behavior seems abnormal. Maybe it's a mistake related to my current version of Drupal (7.67). Or maybe my callback is not structured correctly.