Problem/Motivation

We want to dissale the search field in select2 if only a limitted amount of options is present.

For example:

$elements['salutation'] = [
      '#type' => 'select',
      '#attributes' => ['data-options' => ['{"minimumResultsForSearch": 8}']],
      '#options' => [
        'Frau' => 'Frau',
        'Herr' => 'Herr'
      ],
      '#title' => t('Salutation'),
    ];

Steps to reproduce

Add data-options attribute to any webform select field.

Proposed resolution

fix web/modules/contrib/webform/js/webform.element.select2.js line 59

current:

options = $.extend(true, options, JSON.parse($input.attr('data-options')));

fxed:

options = $.extend(true, options, JSON.parse($select.attr('data-options')));
CommentFileSizeAuthor
#2 webform_custom_select2.patch707 bytesschoenef

Comments

schoenef created an issue. See original summary.

schoenef’s picture

Issue summary: View changes
StatusFileSize
new707 bytes

This patch fixes the issue.

liam morland’s picture

Version: 6.3.0-beta7 » 6.3.x-dev
Status: Active » Closed (duplicate)
Related issues: +#3567475: Impossible to add custom options to Select2 due to undefined variable

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.