I am trying to use Mutliselect via FAPI with D7.

I am adding a Multiselect element in hook_form_alter. I traced the program and found that the $element array returned by _multiselect_build_widget_code has the correct values and the values stay correct all the way until the element is output to HTML.

At that point (see below), the
for the Selected Options has an attribute default_value which has the correct indexes for all of the selected rows, but the values are wrong and there are only 2 options whereas the default value lists 3!

I assume this is a problem with the javascript, but I don't know js well enough to find the error. Any help would be greatly appreciated!!!

----------------------------------------------------

Here is partial html generated by Multiselect:

<select multiple="multiple" name="field_gencat[und][]" id="field_gencat[und]" size="15" default_value="fulltext title 5 54 69" required="1" class="form-multiselect required field_gencat[und]_sel multiselect_sel"><option value="5">Award or Trophy</option>
<option value="6">B/W</option>
</select>

Comments

attheshow’s picture

Title: Not working » Need help with FAPI implementation
Category: bug » support
Jetson’s picture

I tried the development version which solved the problem but created another - neither of the buttons work, so the user cannot add or remove items from the selected list! Thx

Jetson’s picture

Hi attheshow-

I really could use your help! I am trying to debug the development version of multiselect for drupal 7 and seemed to have narrowed the issue down to the javascript. I am using Drupal 7 that has jQuery version 1.4.4.

First problem: I am using hook_form_alter to change the basic node edit form. like so:

$form['field_gencat']['und'] = array(
		    '#type' => 'multiselect',
		    '#title' => t('Tags'),
		    '#multiple' => TRUE,
		    '#size' => 15,
		    '#required' => TRUE,
                    .....

so the class for the selected select box is field_gencat[und]. Javascript does not seem to like the square brackets. Not sure how to get around this?

Second problem: When I pass multiselect_sel the moveSelectionTo function, this.options returns undefined. I also tried this in the console of my browser. I'm feeling my way in the dark with javascript, I am a amateur. Is it possible that this is not working with jQuery 1.4.4?

Thanks!

boychev’s picture

Issue summary: View changes

For the square brackets: https://www.drupal.org/node/2744127