I have found in Project Notes only next information:
" Instead of providing its own Field API widget, this module piggybacks on existing field widgets through form alter hooks. That helps keep the code simple, and free from duplication of existing widget logic"
I wonder if somebody could help me with this task?

Comments

willvincent’s picture

This can be used with FAPI fields already, basically all that's required is to add the same extra config that is added by jquery_ui_multiselect_field_widget_options_select_form_alter().

Module requirements remain, of course. I also found that adding height and width parameters is necessary otherwise the replaced fapi field won't show any of its contents.

Here's a before/after example for a select element:

  $form['tag_filter'] = array(
    '#title'         => t('Filter by tag(s)'),
    '#type'          => 'select',
    '#multiple'      => TRUE,
    '#options'       => $tags,
    '#default_value' => $default_value,
  );

And now with the extra config to make the multi-select work:

  $form['tag_filter'] = array(
    '#title'         => t('Filter by tag(s)'),
    '#type'          => 'select',
    '#multiple'      => TRUE,
    '#options'       => $tags,
    '#default_value' => $default_value,
    '#attached'      => array(
      'library' => array(
        array('jquery_ui_multiselect', 'jquery_ui_multiselect')
      ),
    ),
    '#attributes' => array(
      'class' => array(
        'jquery-ui-multiselect'
      ),
      'data-jquery-ui-multiselect' => drupal_json_encode(
        array(
          'sortable'                => TRUE,
          'dragToAdd'               => TRUE,
          'searchable'              => TRUE,
          'doubleClickable'         => TRUE,
          'includeRemoveAll'        => TRUE,
          'includeAddAll'           => TRUE,
          'selectedContainerOnLeft' => FALSE,
          'height'                  => 220,
          'width'                   => 440,
        )
      ),
    ),
  );
alfa_ru’s picture

Thanks, it works.

avpaderno’s picture

Assigned: alfa_ru » Unassigned
Category: Task » Support request
Status: Active » Fixed
Issue tags: -How to use jquery ui multiselect from form api

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.