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

fix(typeahead): run validators manually on select #3352

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: 12 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,18 @@ describe('typeahead tests', function () {
$(match).click();
$scope.$digest();
});

it('issue #3311 - should trigger validation if filter value equal to list value', function() {

var element = prepareInputEl('<form name="form"><input name="input" ng-model="result" typeahead="item for item in source | filter:$viewValue"></form>');

changeInputValueTo(element, 'foo');

var match = $(findMatches(element)[0]).find('a')[0];
$(match).click();

expect($scope.form.input.$error.parse).toBeUndefined();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a check for the $error before the click as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsed error was introduced in 1.3, so it's impossible to test it in current environment ( angular 1.2.16 )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sagens42 we've updated the project to AngularJS 1.3 recently

});
});

describe('input formatting', function () {
Expand Down
1 change: 1 addition & 0 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,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