Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
feat(ngModel): support the input[type="search"] field
Browse files Browse the repository at this point in the history
Closes #466
  • Loading branch information
matsko committed Jan 31, 2014
1 parent 500446d commit ff736d9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/directive/ng_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class InputCheckboxDirective {
@NgDirective(selector: 'input[type=url][ng-model]')
@NgDirective(selector: 'input[type=email][ng-model]')
@NgDirective(selector: 'input[type=number][ng-model]')
@NgDirective(selector: 'input[type=search][ng-model]')
class InputTextLikeDirective {
final dom.Element inputElement;
final NgModel ngModel;
Expand Down
40 changes: 39 additions & 1 deletion test/directive/ng_model_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('ng-model', () {
}));
});

describe('type="textarea"', () {
describe('textarea', () {
it('should update textarea value from model', inject(() {
_.compile('<textarea ng-model="model">');
_.rootScope.$digest();
Expand Down Expand Up @@ -296,6 +296,44 @@ describe('ng-model', () {
expect(blueBtn.checked).toBe(false);
}));
});

describe('type="search"', () {
it('should update input value from model', inject(() {
_.compile('<input type="search" ng-model="model">');
_.rootScope.$digest();

expect((_.rootElement as dom.InputElement).value).toEqual('');

_.rootScope.$apply('model = "matias"');
expect((_.rootElement as dom.InputElement).value).toEqual('matias');
}));

it('should render null as the empty string', inject(() {
_.compile('<input type="search" ng-model="model">');
_.rootScope.$digest();

expect((_.rootElement as dom.InputElement).value).toEqual('');

_.rootScope.$apply('model = null');
expect((_.rootElement as dom.InputElement).value).toEqual('');
}));

it('should update model from the input value', inject(() {
_.compile('<input type="search" ng-model="model" probe="p">');
Probe probe = _.rootScope.p;
var ngModel = probe.directive(NgModel);
InputElement inputElement = probe.element;

inputElement.value = 'xzy';
_.triggerEvent(inputElement, 'change');
expect(_.rootScope.model).toEqual('xzy');

inputElement.value = '123';
var input = probe.directive(InputTextLikeDirective);
input.processValue();
expect(_.rootScope.model).toEqual('123');
}));
});

describe('contenteditable', () {
it('should update content from model', inject(() {
Expand Down

0 comments on commit ff736d9

Please sign in to comment.