Skip to content

Commit 9b0cd2b

Browse files
Merge pull request #1 from colbysargentdesign/blankSortBy
New Setting: blankSortBy
2 parents 6e9f72d + 0163811 commit 9b0cd2b

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

jquery.flexselect.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
allowMismatch: false,
2222
allowMismatchBlank: true, // If "true" a user can backspace such that the value is nothing (even if no blank value was provided in the original criteria)
2323
sortBy: 'score', // 'score' || 'name'
24+
blankSortBy: false, // 'initial' || 'score' || 'name'
2425
preSelection: true,
2526
hideDropdownOnEmptyInput: false,
2627
selectedClass: "flexselect_selected",
@@ -112,11 +113,9 @@
112113
self.hide();
113114
if (self.settings.allowMismatchBlank && $.trim($(this).val()) == '')
114115
self.setValue('');
115-
if (!self.settings.allowMismatch && !self.picked)
116+
else if (!self.settings.allowMismatch && !self.picked)
116117
self.reset();
117118
}
118-
if (self.settings.hideDropdownOnEmptyInput)
119-
self.dropdownList.show();
120119
});
121120

122121
this.dropdownList.mouseover(function(event) {
@@ -169,12 +168,6 @@
169168
self.filterResults();
170169
break;
171170
}
172-
if (self.settings.hideDropdownOnEmptyInput){
173-
if(self.input.val() == "")
174-
self.dropdownList.hide();
175-
else
176-
self.dropdownList.show();
177-
}
178171
});
179172

180173
this.input.keydown(function(event) {
@@ -225,17 +218,31 @@
225218
if (this.score > 0.0) results.push(this);
226219
});
227220
this.results = results;
228-
229-
if (this.settings.sortBy == 'score')
230-
this.sortResultsByScore();
231-
else if (this.settings.sortBy == 'name')
232-
this.sortResultsByName();
221+
222+
if(this.settings.blankSortBy && $.trim(abbreviation) == ''){
223+
if (this.settings.blankSortBy == 'score')
224+
this.sortResultsByScore();
225+
else if (this.settings.blankSortBy == 'name')
226+
this.sortResultsByName();
227+
} else {
228+
if (this.settings.sortBy == 'score')
229+
this.sortResultsByScore();
230+
else if (this.settings.sortBy == 'name')
231+
this.sortResultsByName();
232+
}
233233

234234
this.renderDropdown();
235235
this.markFirst();
236236
this.lastAbbreviation = abbreviation;
237237
this.picked = false;
238238
this.allowMouseMove = false;
239+
240+
if (this.settings.hideDropdownOnEmptyInput){
241+
if(this.input.val() == "")
242+
this.dropdown.hide();
243+
else
244+
this.dropdown.show();
245+
}
239246
},
240247

241248
sortResultsByScore: function() {

0 commit comments

Comments
 (0)