$form['name'] = array(
  '#type' => 'select2',
  '#title' => 'Some title',
  '#options' => [1 => 'One', 2 => 'Two'],
  '#empty_option' => '[custom empty value]',
  '#empty_value' => -1,
  '#placeholder' => 'this property is ignored',
);

'#empty_option' and '#empty_value' options are ignored rendering element with '- none -' option.
'#placeholder' property is being ignored too.

Comments

f1mishutka created an issue. See original summary.

f1mishutka’s picture

StatusFileSize
new679 bytes
f1mishutka’s picture

Status: Active » Needs review
f1mishutka’s picture

Assigned: f1mishutka » Unassigned
f1mishutka’s picture

Version: 8.x-1.7 » 8.x-1.x-dev
Issue summary: View changes
StatusFileSize
new1.88 KB

Added proper handling of '#placeholder' property also.

f1mishutka’s picture

Title: #empty_value and #empty_option properties are ignored » '#empty_value', '#empty_option' and '#placeholder' properties are ignored
Issue tags: +placeholder
f1mishutka’s picture

Issue summary: View changes
chr.fritsch’s picture

Status: Needs review » Needs work

Thank you for this issue.

Before I am giving this a deeper review, it would be nice to fix the tests in the PR (https://github.com/thunder/select2/pull/87/files)

f1mishutka’s picture

StatusFileSize
new1.94 KB

it would be nice to fix the tests in the PR

Codestyle fixed

chr.fritsch’s picture

Thank you, the tests are green 👍. I think we need a few simple tests and then we are done.

For example a small placeholder check could be added to Drupal\Tests\select2\Unit\Element\Select2Test. And the empty options could be checked in Drupal\Tests\select2\Kernel\Element\Select2Test

f1mishutka’s picture

Hi Christian,

I'm not so good in writing Drupal tests. Anyway I tried to do my best following your suggestions.

Pushed commits to GitHub:
1. Could you please review the changes?
2. Do I need to attach separate patch file for this changes here?

Thank you!

f1mishutka’s picture

Status: Needs work » Needs review
chr.fritsch’s picture

Status: Needs review » Needs work

The tests are not working

chr.fritsch’s picture

Status: Needs work » Needs review

Here is another fix: https://github.com/thunder/select2/pull/94

Select2 has actually an equivalent for empty_option and empty_value

chr.fritsch’s picture

Status: Needs review » Reviewed & tested by the community

  • chr.fritsch authored a7be3df on 8.x-1.x
    Issue #3123254 by f1mishutka, chr.fritsch, daniel.bosen: '#empty_value...
chr.fritsch’s picture

Status: Reviewed & tested by the community » Fixed

Fixed

surya.s’s picture

#14 works for me.

Status: Fixed » Closed (fixed)

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

f1mishutka’s picture

Unfortunately #14 does not fix this issue 100%.

Created new issue issue 3171604 with details.
Thank you!