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

fix(typeahead): reset 'parse' validation key #3406

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,16 @@ describe('typeahead tests', function () {
$(match).click();
$scope.$digest();
});

it('issue #3166 - should set \'parse\' key as valid when selecting a perfect match and not editable', function () {
var element = prepareInputEl('<div ng-form="test"><input name="typeahead" ng-model="result" typeahead="state as state.name for state in states | filter:$viewValue" typeahead-editable="false"></div>');
var inputEl = findInput(element);

changeInputValueTo(element, 'Alaska');
triggerKeyDown(element, 13);

expect($scope.test.typeahead.$error.parse).toBeUndefined();
});
});

describe('input formatting', function () {
Expand Down Expand Up @@ -741,7 +751,7 @@ describe('typeahead tests', function () {
};
var element = prepareInputEl('<div><input ng-model="result" ng-keydown="keyDownEvent = $event" typeahead="item for item in source | filter:$viewValue" typeahead-on-select="onSelect($item, $model, $label)" typeahead-focus-first="false"></div>');
changeInputValueTo(element, 'b');

// enter key should not be captured when nothing is focused
triggerKeyDown(element, 13);
expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy();
Expand Down
5 changes: 3 additions & 2 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
//we need to propagate user's query so we can higlight matches
scope.query = undefined;

//Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later
//Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later
var timeoutPromise;

var scheduleSearchWithTimeout = function(inputValue) {
Expand Down Expand Up @@ -252,6 +252,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
model = parserResult.modelMapper(originalScope, locals);
$setModelValue(originalScope, model);
modelCtrl.$setValidity('editable', true);
modelCtrl.$setValidity('parse', true);

onSelectCallback(originalScope, {
$item: item,
Expand Down Expand Up @@ -326,7 +327,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
});

var $popup = $compile(popUpEl)(scope);

if (appendToBody) {
$document.find('body').append($popup);
} else {
Expand Down