mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-28 21:05:43 +08:00
revert: fix(input): always format viewValue as a string inputs with text controls
This reverts commit 1b8b41ad23.
This is a breaking change.
This commit is contained in:
@@ -475,18 +475,7 @@ function addNativeHtml5Validators(ctrl, validatorName, badFlags, ignoreFlags, va
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stringBasedInputType(ctrl) {
|
function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
|
||||||
ctrl.$formatters.push(function stringifier(value) {
|
|
||||||
return ctrl.$isEmpty(value) ? value : value.toString();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function textInputType(scope, element, attr,ctrl, $sniffer, $browser) {
|
|
||||||
baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
|
|
||||||
stringBasedInputType(ctrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
|
|
||||||
var validity = element.prop(VALIDITY_STATE_PROPERTY);
|
var validity = element.prop(VALIDITY_STATE_PROPERTY);
|
||||||
var placeholder = element[0].placeholder, noevent = {};
|
var placeholder = element[0].placeholder, noevent = {};
|
||||||
var type = lowercase(element[0].type);
|
var type = lowercase(element[0].type);
|
||||||
@@ -1546,8 +1535,6 @@ var requiredDirective = function() {
|
|||||||
*/
|
*/
|
||||||
var ngListDirective = function() {
|
var ngListDirective = function() {
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
|
||||||
priority: 100,
|
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, element, attr, ctrl) {
|
link: function(scope, element, attr, ctrl) {
|
||||||
var match = /\/(.*)\//.exec(attr.ngList),
|
var match = /\/(.*)\//.exec(attr.ngList),
|
||||||
|
|||||||
@@ -310,87 +310,6 @@ describe('ngModel', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should always format the viewValue as a string for a blank input type when the value is present',
|
|
||||||
inject(function($compile, $rootScope, $sniffer) {
|
|
||||||
|
|
||||||
var form = $compile('<form name="form"><input name="field" ng-model="val" /></form>')($rootScope);
|
|
||||||
|
|
||||||
$rootScope.val = 123;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBe('123');
|
|
||||||
|
|
||||||
$rootScope.val = null;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBe(null);
|
|
||||||
|
|
||||||
dealoc(form);
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
it('should always format the viewValue as a string for a `text` input type when the value is present',
|
|
||||||
inject(function($compile, $rootScope, $sniffer) {
|
|
||||||
|
|
||||||
var form = $compile('<form name="form"><input type="text" name="field" ng-model="val" /></form>')($rootScope);
|
|
||||||
$rootScope.val = 123;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBe('123');
|
|
||||||
|
|
||||||
$rootScope.val = null;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBe(null);
|
|
||||||
|
|
||||||
$rootScope.val = undefined;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBeUndefined();
|
|
||||||
|
|
||||||
dealoc(form);
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
it('should always format the viewValue as a string for an `email` input type when the value is present',
|
|
||||||
inject(function($compile, $rootScope, $sniffer) {
|
|
||||||
|
|
||||||
var fakeEmail = {};
|
|
||||||
fakeEmail.toString = function() { return 'fake@email'; };
|
|
||||||
var form = $compile('<form name="form"><input type="email" name="field" ng-model="val" /></form>')($rootScope);
|
|
||||||
$rootScope.val = fakeEmail;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBe('fake@email');
|
|
||||||
|
|
||||||
$rootScope.val = null;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBe(null);
|
|
||||||
|
|
||||||
$rootScope.val = undefined;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBeUndefined();
|
|
||||||
|
|
||||||
dealoc(form);
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
it('should always format the viewValue as a string for a `url` input type when the value is present',
|
|
||||||
inject(function($compile, $rootScope, $sniffer) {
|
|
||||||
|
|
||||||
var fakeUrl = {};
|
|
||||||
fakeUrl.toString = function() { return 'https://www.angularjs.org'; };
|
|
||||||
var form = $compile('<form name="form"><input type="url" name="field" ng-model="val" /></form>')($rootScope);
|
|
||||||
$rootScope.val = fakeUrl;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBe('https://www.angularjs.org');
|
|
||||||
|
|
||||||
$rootScope.val = null;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBe(null);
|
|
||||||
|
|
||||||
$rootScope.val = undefined;
|
|
||||||
$rootScope.$digest();
|
|
||||||
expect($rootScope.form.field.$viewValue).toBeUndefined();
|
|
||||||
|
|
||||||
dealoc(form);
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
it('should register/deregister a nested ngModel with parent form when entering or leaving DOM',
|
it('should register/deregister a nested ngModel with parent form when entering or leaving DOM',
|
||||||
inject(function($compile, $rootScope) {
|
inject(function($compile, $rootScope) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user