$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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | empty_option-3123254-9.patch | 1.94 KB | f1mishutka |
Comments
Comment #2
f1mishutka commentedComment #3
f1mishutka commentedComment #4
f1mishutka commentedComment #5
f1mishutka commentedAdded proper handling of '#placeholder' property also.
Comment #6
f1mishutka commentedComment #7
f1mishutka commentedComment #8
chr.fritschThank 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)
Comment #9
f1mishutka commentedCodestyle fixed
Comment #10
chr.fritschThank 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
Comment #11
f1mishutka commentedHi 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!
Comment #12
f1mishutka commentedComment #13
chr.fritschThe tests are not working
Comment #14
chr.fritschHere is another fix: https://github.com/thunder/select2/pull/94
Select2 has actually an equivalent for empty_option and empty_value
Comment #16
chr.fritschComment #18
chr.fritschFixed
Comment #19
surya.s commented#14 works for me.
Comment #21
f1mishutka commentedUnfortunately #14 does not fix this issue 100%.
Created new issue issue 3171604 with details.
Thank you!