From 739cc659a16da603be3502a352738e19e539f2b4 Mon Sep 17 00:00:00 2001 From: Jason Bouffard <181576+jasonbouffard@users.noreply.github.com> Date: Fri, 6 Dec 2024 18:15:45 -0500 Subject: [PATCH] when sync(true) is called, it should retain allowEmptyOption setting --- src/tom-select.ts | 2 +- test/support/base.js | 1 + test/tests/api.js | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/tom-select.ts b/src/tom-select.ts index 697949d3..0031e3df 100644 --- a/src/tom-select.ts +++ b/src/tom-select.ts @@ -541,7 +541,7 @@ export default class TomSelect extends MicroPlugin(MicroEvent){ */ sync(get_settings:boolean=true):void{ const self = this; - const settings = get_settings ? getSettings( self.input, {delimiter:self.settings.delimiter} as RecursivePartial ) : self.settings; + const settings = get_settings ? getSettings( self.input, {delimiter:self.settings.delimiter,allowEmptyOption:self.settings.allowEmptyOption} as RecursivePartial ) : self.settings; self.setupOptions(settings.options,settings.optgroups); diff --git a/test/support/base.js b/test/support/base.js index 265e54be..c93abc0f 100644 --- a/test/support/base.js +++ b/test/support/base.js @@ -37,6 +37,7 @@ var teardownLast = function(){ var test_html = { AB_Multi : '', AB_Single : '', + AB_Single_Empty : '', AB_Single_Long : '', } diff --git a/test/tests/api.js b/test/tests/api.js index e6a4bef1..65a0af8d 100644 --- a/test/tests/api.js +++ b/test/tests/api.js @@ -1007,5 +1007,14 @@ assert.equal(test.instance.items.length, 1,'should have one item'); assert.equal(test.instance.items[0], 'new'); }); + + it_n('sync() should retain empty value',function(){ + const test = setup_test('AB_Single_Empty',{allowEmptyOption:true}); + var opt_count = Object.keys(test.instance.options).length; + test.instance.sync(true); + + assert.equal(test.instance.items[0], '', 'empty item should remain'); + assert.equal( Object.keys(test.instance.options).length, opt_count, 'option count remains'); + }); }); });