Optional multiselect field, hide the - None- option I am working on a form made mostly of multi-select fields, which are optional for the user to choose.

The multi-select fields work fine in general; however I really need to hide the -None- option in the multi-select fields which are not required for user to select. I can override it and change the text but thats not the point, since user can still select the -None- value in the process of selection, even tho it wont show after node is saved.

It just looks a bit confusing, even though it works as it should; users can select both the -None- option along with other options available and that makes the whole form different from what I want.

Here is an image of an example field showing what I mean.


  





  


I tried searching through the CCK module, but I couldn't really find anything.
To get rid of "- None -" from selected field of a selected form, use:

function MYMODULE_form_FORM_ID_alter(&amp;$form, &amp;$form_state, $form_id) {
    unset($form['field_name'][LANGUAGE_NONE]['#options']['_none']);
}


Of course for many fields it's inconvenient, but if they all share common parent (fieldset), you can iterate using foreach like:

function MYMODULE_form_FORM_ID_alter(&amp;$form, &amp;$form_state, $form_id) {
    foreach( element_children($form['fieldset_name']) as $key =&gt; $child) {
       unset($form['fieldset_name'][$key][LANGUAGE_NONE]['#options']['_none']);
    }
}


This is not a ready code, just a sketch. Hints to make it work:


Unset elements of original $form, not $child generated by foreach.
Test if what you want to unset is there at all.
dpr() or var_dump() to see what's the exact structure you are working with.


You will need to wrap these into a Drupal custom module. Read Module developer's guide, especially Creating Drupal 7 modules, and hook_form_alter() API reference if you need more backgroung.

Inspired by this answer.