Skip to content

Commit

Permalink
when sync(true) is called, it should retain allowEmptyOption setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbouffard committed Dec 6, 2024
1 parent fadaeb4 commit 739cc65
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tom-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TomSettings> ) : self.settings;
const settings = get_settings ? getSettings( self.input, {delimiter:self.settings.delimiter,allowEmptyOption:self.settings.allowEmptyOption} as RecursivePartial<TomSettings> ) : self.settings;

self.setupOptions(settings.options,settings.optgroups);

Expand Down
1 change: 1 addition & 0 deletions test/support/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var teardownLast = function(){
var test_html = {
AB_Multi : '<select multiple><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>',
AB_Single : '<select><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>',
AB_Single_Empty : '<select><option value="">empty</option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>',
AB_Single_Long : '<select><option>a</option><option>b</option><option>c</option><option>d</option><option>e</option><option>f</option><option>g</option><option>h</option><option>i</option><option>j</option><option>k</option><option>l</option><option>m</option><option>n</option><option>o</option><option>p</option></select>',
}

Expand Down
9 changes: 9 additions & 0 deletions test/tests/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit 739cc65

Please sign in to comment.