Skip to content

Commit 7984747

Browse files
author
Ruud Seberechts
committed
[Autocomplete] Only activate clear button plugin when there is a placeholder option
1 parent c9bf5ee commit 7984747

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Autocomplete/assets/dist/controller.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1515
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1616
PERFORMANCE OF THIS SOFTWARE.
1717
***************************************************************************** */
18-
/* global Reflect, Promise, SuppressedError, Symbol */
18+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1919

2020

2121
function __classPrivateFieldGet(receiver, state, kind, f) {
@@ -227,7 +227,10 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
227227
const plugins = {};
228228
const isMultiple = !this.selectElement || this.selectElement.multiple;
229229
if (!this.formElement.disabled && !isMultiple) {
230-
plugins.clear_button = { title: '' };
230+
const firstOption = this.selectElement.options[0];
231+
if (firstOption && firstOption.value === '') {
232+
plugins.clear_button = { title: '' };
233+
}
231234
}
232235
if (isMultiple) {
233236
plugins.remove_button = { title: '' };

src/Autocomplete/assets/src/controller.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,14 @@ export default class extends Controller {
127127
#getCommonConfig(): Partial<TomSettings> {
128128
const plugins: TPluginHash = {};
129129

130-
// multiple values excepted if this is NOT A select (i.e. input) or a multiple select
130+
// Multiple values expected if this is NOT A select (i.e. input) or a multiple select
131131
const isMultiple = !this.selectElement || this.selectElement.multiple;
132132
if (!this.formElement.disabled && !isMultiple) {
133-
plugins.clear_button = { title: '' };
133+
// Only activate clear button plugin when there is a placeholder option
134+
const firstOption = this.selectElement.options[0];
135+
if (firstOption && firstOption.value === '') {
136+
plugins.clear_button = { title: '' };
137+
}
134138
}
135139

136140
if (isMultiple) {

0 commit comments

Comments
 (0)