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

Commit bba3f27

Browse files
pdesgaretswesleycho
authored andcommitted
fix(typeahead): use $setViewValue on blur
Use $setViewValue instead of setting directly $viewValue to '', to make new value go through validators. Closes #5769 Fixes #5694
1 parent 3d7191c commit bba3f27

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/typeahead/test/typeahead.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ describe('typeahead tests', function() {
315315
expect($scope.form.input.$error.parse).toBeFalsy();
316316
});
317317

318+
it('should go through other validators after blur for typeahead-editable="false"', function () {
319+
var element = prepareInputEl(
320+
'<div><form name="form">' +
321+
'<input name="input" ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-editable="false" required>' +
322+
'</form></div>');
323+
var inputEl = findInput(element);
324+
325+
changeInputValueTo(element, 'not in matches');
326+
expect($scope.result).toEqual(undefined);
327+
expect(inputEl.val()).toEqual('not in matches');
328+
inputEl.blur(); // input loses focus
329+
expect($scope.result).toEqual(undefined);
330+
expect($scope.form.input.$error.required).toBeTruthy();
331+
});
332+
318333
it('should clear view value when no value selected for typeahead-editable="false" typeahead-select-on-blur="false"', function () {
319334
var element = prepareInputEl('<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-editable="false" typeahead-select-on-blur="false"></div>');
320335
var inputEl = findInput(element);

src/typeahead/typeahead.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
441441
});
442442
}
443443
if (!isEditable && modelCtrl.$error.editable) {
444-
modelCtrl.$viewValue = '';
444+
modelCtrl.$setViewValue();
445445
// Reset validity as we are clearing
446446
modelCtrl.$setValidity('editable', true);
447447
modelCtrl.$setValidity('parse', true);

0 commit comments

Comments
 (0)