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

Commit a91bbca

Browse files
committed
fix(ngModel): add input type tel to ngModel directive
1 parent 9cb74d4 commit a91bbca

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

lib/directive/ng_model.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class InputCheckbox {
317317
/**
318318
* Usage:
319319
*
320-
* <input type="text|url|password|email" ng-model="myModel">
320+
* <input type="text|url|password|email|search|tel" ng-model="myModel">
321321
* <textarea ng-model="myModel"></textarea>
322322
*
323323
* This creates a two-way binding between any string-based input element
@@ -333,6 +333,7 @@ class InputCheckbox {
333333
@Decorator(selector: 'input[type=url][ng-model]')
334334
@Decorator(selector: 'input[type=email][ng-model]')
335335
@Decorator(selector: 'input[type=search][ng-model]')
336+
@Decorator(selector: 'input[type=tel][ng-model]')
336337
class InputTextLike {
337338
final dom.Element inputElement;
338339
final NgModel ngModel;

test/directive/ng_model_spec.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,60 @@ void main() {
10321032
});
10331033
});
10341034

1035+
describe('type="tel"', () {
1036+
it('should update input value from model', () {
1037+
_.compile('<input type="tel" ng-model="model">');
1038+
_.rootScope.apply();
1039+
1040+
expect((_.rootElement as dom.InputElement).value).toEqual('');
1041+
1042+
_.rootScope.apply('model = "matias"');
1043+
expect((_.rootElement as dom.InputElement).value).toEqual('matias');
1044+
});
1045+
1046+
it('should render null as the empty string', () {
1047+
_.compile('<input type="tel" ng-model="model">');
1048+
_.rootScope.apply();
1049+
1050+
expect((_.rootElement as dom.InputElement).value).toEqual('');
1051+
1052+
_.rootScope.apply('model = null');
1053+
expect((_.rootElement as dom.InputElement).value).toEqual('');
1054+
});
1055+
1056+
it('should update model from the input value', () {
1057+
_.compile('<input type="tel" ng-model="model" probe="p">');
1058+
Probe probe = _.rootScope.context['p'];
1059+
var ngModel = probe.directive(NgModel);
1060+
InputElement inputElement = probe.element;
1061+
1062+
inputElement.value = 'xzy';
1063+
_.triggerEvent(inputElement, 'change');
1064+
expect(_.rootScope.context['model']).toEqual('xzy');
1065+
1066+
inputElement.value = '123';
1067+
var input = probe.directive(InputTextLike);
1068+
input.processValue();
1069+
expect(_.rootScope.context['model']).toEqual('123');
1070+
});
1071+
1072+
it('should only render the input value upon the next digest', (Scope scope) {
1073+
_.compile('<input type="tel" ng-model="model" probe="p">');
1074+
Probe probe = _.rootScope.context['p'];
1075+
var ngModel = probe.directive(NgModel);
1076+
InputElement inputElement = probe.element;
1077+
1078+
ngModel.render('xyz');
1079+
scope.context['model'] = 'xyz';
1080+
1081+
expect(inputElement.value).not.toEqual('xyz');
1082+
1083+
scope.apply();
1084+
1085+
expect(inputElement.value).toEqual('xyz');
1086+
});
1087+
});
1088+
10351089
describe('contenteditable', () {
10361090
it('should update content from model', () {
10371091
_.compile('<p contenteditable ng-model="model">');

0 commit comments

Comments
 (0)