Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1850f59

Browse files
committed
revert: fix(input): always format viewValue as a string inputs with text controls
This reverts commit 1b8b41a. This is a breaking change.
1 parent 1f18285 commit 1850f59

File tree

2 files changed

+1
-95
lines changed

2 files changed

+1
-95
lines changed

src/ng/directive/input.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -475,18 +475,7 @@ function addNativeHtml5Validators(ctrl, validatorName, badFlags, ignoreFlags, va
475475
}
476476
}
477477

478-
function stringBasedInputType(ctrl) {
479-
ctrl.$formatters.push(function stringifier(value) {
480-
return ctrl.$isEmpty(value) ? value : value.toString();
481-
});
482-
}
483-
484-
function textInputType(scope, element, attr,ctrl, $sniffer, $browser) {
485-
baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
486-
stringBasedInputType(ctrl);
487-
}
488-
489-
function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
478+
function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
490479
var validity = element.prop(VALIDITY_STATE_PROPERTY);
491480
var placeholder = element[0].placeholder, noevent = {};
492481
var type = lowercase(element[0].type);
@@ -1546,8 +1535,6 @@ var requiredDirective = function() {
15461535
*/
15471536
var ngListDirective = function() {
15481537
return {
1549-
restrict: 'A',
1550-
priority: 100,
15511538
require: 'ngModel',
15521539
link: function(scope, element, attr, ctrl) {
15531540
var match = /\/(.*)\//.exec(attr.ngList),

test/ng/directive/inputSpec.js

-81
Original file line numberDiff line numberDiff line change
@@ -310,87 +310,6 @@ describe('ngModel', function() {
310310
}));
311311

312312

313-
it('should always format the viewValue as a string for a blank input type when the value is present',
314-
inject(function($compile, $rootScope, $sniffer) {
315-
316-
var form = $compile('<form name="form"><input name="field" ng-model="val" /></form>')($rootScope);
317-
318-
$rootScope.val = 123;
319-
$rootScope.$digest();
320-
expect($rootScope.form.field.$viewValue).toBe('123');
321-
322-
$rootScope.val = null;
323-
$rootScope.$digest();
324-
expect($rootScope.form.field.$viewValue).toBe(null);
325-
326-
dealoc(form);
327-
}));
328-
329-
330-
it('should always format the viewValue as a string for a `text` input type when the value is present',
331-
inject(function($compile, $rootScope, $sniffer) {
332-
333-
var form = $compile('<form name="form"><input type="text" name="field" ng-model="val" /></form>')($rootScope);
334-
$rootScope.val = 123;
335-
$rootScope.$digest();
336-
expect($rootScope.form.field.$viewValue).toBe('123');
337-
338-
$rootScope.val = null;
339-
$rootScope.$digest();
340-
expect($rootScope.form.field.$viewValue).toBe(null);
341-
342-
$rootScope.val = undefined;
343-
$rootScope.$digest();
344-
expect($rootScope.form.field.$viewValue).toBeUndefined();
345-
346-
dealoc(form);
347-
}));
348-
349-
350-
it('should always format the viewValue as a string for an `email` input type when the value is present',
351-
inject(function($compile, $rootScope, $sniffer) {
352-
353-
var fakeEmail = {};
354-
fakeEmail.toString = function() { return 'fake@email'; };
355-
var form = $compile('<form name="form"><input type="email" name="field" ng-model="val" /></form>')($rootScope);
356-
$rootScope.val = fakeEmail;
357-
$rootScope.$digest();
358-
expect($rootScope.form.field.$viewValue).toBe('fake@email');
359-
360-
$rootScope.val = null;
361-
$rootScope.$digest();
362-
expect($rootScope.form.field.$viewValue).toBe(null);
363-
364-
$rootScope.val = undefined;
365-
$rootScope.$digest();
366-
expect($rootScope.form.field.$viewValue).toBeUndefined();
367-
368-
dealoc(form);
369-
}));
370-
371-
372-
it('should always format the viewValue as a string for a `url` input type when the value is present',
373-
inject(function($compile, $rootScope, $sniffer) {
374-
375-
var fakeUrl = {};
376-
fakeUrl.toString = function() { return 'https://www.angularjs.org'; };
377-
var form = $compile('<form name="form"><input type="url" name="field" ng-model="val" /></form>')($rootScope);
378-
$rootScope.val = fakeUrl;
379-
$rootScope.$digest();
380-
expect($rootScope.form.field.$viewValue).toBe('https://www.angularjs.org');
381-
382-
$rootScope.val = null;
383-
$rootScope.$digest();
384-
expect($rootScope.form.field.$viewValue).toBe(null);
385-
386-
$rootScope.val = undefined;
387-
$rootScope.$digest();
388-
expect($rootScope.form.field.$viewValue).toBeUndefined();
389-
390-
dealoc(form);
391-
}));
392-
393-
394313
it('should register/deregister a nested ngModel with parent form when entering or leaving DOM',
395314
inject(function($compile, $rootScope) {
396315

0 commit comments

Comments
 (0)