Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When sync(true) is called, it should retain allowEmptyOption setting #833

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});
});