|
21 | 21 | allowMismatch: false,
|
22 | 22 | 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)
|
23 | 23 | sortBy: 'score', // 'score' || 'name'
|
24 |
| - blankSortBy: false, // 'initial' || 'score' || 'name' |
| 24 | + blankSortBy: 'initial', // 'score' || 'name' || 'initial' |
25 | 25 | preSelection: true,
|
26 | 26 | hideDropdownOnEmptyInput: false,
|
27 | 27 | selectedClass: "flexselect_selected",
|
|
208 | 208 |
|
209 | 209 | filterResults: function() {
|
210 | 210 | var showDisabled = this.settings.showDisabledOptions;
|
211 |
| - var abbreviation = this.input.val(); |
| 211 | + var abbreviation = $.trim(this.input.val()); |
| 212 | + var sortByMechanism = (abbreviation == "") ? this.settings.blankSortBy : this.settings.sortBy; |
212 | 213 | if (abbreviation == this.lastAbbreviation) return;
|
213 | 214 |
|
214 | 215 | var results = [];
|
|
218 | 219 | if (this.score > 0.0) results.push(this);
|
219 | 220 | });
|
220 | 221 | this.results = results;
|
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 |
| - } |
233 | 222 |
|
| 223 | + this.sortResultsBy(sortByMechanism); |
234 | 224 | this.renderDropdown();
|
235 | 225 | this.markFirst();
|
236 | 226 | this.lastAbbreviation = abbreviation;
|
237 | 227 | this.picked = false;
|
238 | 228 | this.allowMouseMove = false;
|
239 |
| - |
| 229 | + |
240 | 230 | if (this.settings.hideDropdownOnEmptyInput){
|
241 |
| - if(this.input.val() == "") |
| 231 | + if (abbreviation == "") |
242 | 232 | this.dropdown.hide();
|
243 | 233 | else
|
244 | 234 | this.dropdown.show();
|
245 | 235 | }
|
246 | 236 | },
|
247 | 237 |
|
| 238 | + sortResultsBy: function(mechanism) { |
| 239 | + if (mechanism == "score") { |
| 240 | + this.sortResultsByScore(); |
| 241 | + } else if (mechanism == "name") { |
| 242 | + this.sortResultsByName(); |
| 243 | + } |
| 244 | + }, |
| 245 | + |
248 | 246 | sortResultsByScore: function() {
|
249 | 247 | this.results.sort(function(a, b) { return b.score - a.score; });
|
250 | 248 | },
|
|
0 commit comments