Hi,
I would like to use multilselect in my own module.
However, it doesn't show up.
Can you please add some basic documentation what the module is for, how it can be used, with some example code snippets ?
Currently I am trying to use it (without success) in hook_form() this way:
$form['gnid'] = array(
'#type' => 'multiselect',
'#title' => t('Group'),
'#default_value' => $subscribedGroupsArray,
'#options' => $group_array,
'#description' => t('Please choose an option.'),
'#weight' => 6,
'#rows' => 10,
'#multiple' => TRUE
);
What am I doing wrong ?
Comments
Comment #1
michael_kirk commentedHi Arnold,
The multiselect widget is used in conjunction with the CCK nodereference field. It is not part of the forms API, so you cannot specify it as a '#type' in your form array. As I understand it, the only types you can specify within your form element are listed here (drupal 5) : http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/5
To use it, add a new field of type nodereference, then select multiselect as your widget. If you don't know how to do that, take a look at the cck handbook: http://drupal.org/node/101723
If you want to use it in your module, it would have to be a cck module.
That said, I'm not sure how one extends the form API. I would be interested in making this widget more generic and useful. I'll take a look.
Comment #2
jorditr commentedIt would be great if it was a general widget, so useful in many situations. BTW, any plans for a drupal 6 release?
Comment #3
Arnold Schw. commentedHi all,
I made a workaround for this issue myself by simply adding some javascript to the default 'select'. Now the select widget behaves like simpleselect, as seen here: http://labs.mininova.org/simpleselect .
The javascript file looks like this and was pasted into mymodule.js:
The javascript file is added to my custom module by
drupal_add_js(drupal_get_path('module', 'mymodule').'/mymodule.js');The form entry in my custom module is as follows:
Note the #attributes entry, this takes care of the extra javascript actions in the html-select-widget.
And this simply works !
Comment #4
michael_kirk commentedThanks for the code snippet Arnold.
Comment #5
Arnold Schw. commentedThis will not be fixed here, so I'll close this call
Comment #6
desunit commentedI had the same requirements - I wanted to reuse that control in my custom form. After reviewing the multiselect control I've found that you could reuse most of the code and with some tweaking you could integrate it quite easily. First of all define $element:
Then define a multiselect values function:
Invoke multiselect_select_process function and assign the result to your form:
Comment #7
mcfroggie commentedHi!
I am using Drupal 6 and have a problem that would require the use of Multiselect in my own module. Since I am quite new to drupal, I would very much appreciate if someone could point me to the right direction with a chunk of code that I can test.
Comment #8
attheshow commentedThe snippet in comment 6 appears to be for Drupal 6 actually.
Comment #9
kolade.ige commentedThanks Arnold, jQuery did if for me too.