Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 0bcd70a

Browse files
Jefiozieaaronroberson
authored andcommitted
fix(resetSearchInput) multiple didn't clear after selecting (#1761)
* fix(resetSearchInput) multiple didn't clear after selecting Closes #1760
1 parent 919e9c4 commit 0bcd70a

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/uiSelectController.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,8 @@ uis.controller('uiSelectCtrl',
423423
ctrl.close(skipFocusser);
424424
return;
425425
}
426-
_resetSearchInput();
427-
}
428-
426+
}
427+
_resetSearchInput();
429428
$scope.$broadcast('uis:select', item);
430429

431430
var locals = {};
@@ -450,7 +449,7 @@ uis.controller('uiSelectCtrl',
450449
if (!ctrl.open) return;
451450
if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched();
452451
ctrl.open = false;
453-
452+
_resetSearchInput();
454453
$scope.$broadcast('uis:close', skipFocusser);
455454

456455
};

test/select.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,7 @@ describe('ui-select tests', function() {
18121812
if (attrs.groupBy !== undefined) { choicesAttrsHtml += ' group-by="' + attrs.groupBy + '"'; }
18131813
if (attrs.lockChoice !== undefined) { matchesAttrsHtml += ' ui-lock-choice="' + attrs.lockChoice + '"'; }
18141814
if (attrs.removeSelected !== undefined) { attrsHtml += ' remove-selected="' + attrs.removeSelected + '"'; }
1815+
if (attrs.resetSearchInput !== undefined) { attrsHtml += ' reset-search-input="' + attrs.resetSearchInput + '"'; }
18151816
}
18161817

18171818
return compileTemplate(
@@ -2756,6 +2757,39 @@ describe('ui-select tests', function() {
27562757
clickItem(el, 'Wladimir');
27572758
expect(el.scope().$select.selected.length).toBe(2);
27582759
});
2760+
2761+
describe('resetSearchInput option multiple', function () {
2762+
it('should be false by default', function () {
2763+
expect(createUiSelectMultiple().scope().$select.resetSearchInput).toBe(false);
2764+
});
2765+
2766+
it('should be true when set.', function () {
2767+
expect(createUiSelectMultiple({ resetSearchInput: true }).scope().$select.resetSearchInput).toBe(true);
2768+
});
2769+
});
2770+
2771+
describe('Reset the search value', function () {
2772+
it('should clear the search input when resetSearchInput is true', function () {
2773+
var el = createUiSelectMultiple({ resetSearchInput: true });
2774+
$(el).scope().$select.search = 'idontexist';
2775+
$(el).scope().$select.select('idontexist');
2776+
expect($(el).scope().$select.search).toEqual('');
2777+
});
2778+
2779+
it('should not clear the search input when resetSearchInput is false', function () {
2780+
var el = createUiSelectMultiple({ resetSearchInput: false });
2781+
$(el).scope().$select.search = 'idontexist';
2782+
$(el).scope().$select.select('idontexist');
2783+
expect($(el).scope().$select.search).toEqual('idontexist');
2784+
});
2785+
2786+
it('should not clear the search input when resetSearchInput is default set', function () {
2787+
var el = createUiSelectMultiple();
2788+
$(el).scope().$select.search = 'idontexist';
2789+
$(el).scope().$select.select('idontexist');
2790+
expect($(el).scope().$select.search).toEqual('idontexist');
2791+
});
2792+
});
27592793
});
27602794

27612795
it('should add an id to the search input field', function () {

0 commit comments

Comments
 (0)