mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-10 07:44:43 +00:00
validation issues fixed
This commit is contained in:
parent
deb86fe357
commit
6470b48ce0
5 changed files with 30 additions and 11 deletions
13
angular-debug.js
vendored
13
angular-debug.js
vendored
|
|
@ -2839,7 +2839,7 @@ foreach({
|
||||||
element.removeClass('ng-input-indicator-wait');
|
element.removeClass('ng-input-indicator-wait');
|
||||||
scope.$invalidWidgets.markValid(element);
|
scope.$invalidWidgets.markValid(element);
|
||||||
}
|
}
|
||||||
element.data('$validate')(input);
|
element.data('$validate')();
|
||||||
scope.$root.$eval();
|
scope.$root.$eval();
|
||||||
});
|
});
|
||||||
} else if (inputState.inFlight) {
|
} else if (inputState.inFlight) {
|
||||||
|
|
@ -3202,6 +3202,11 @@ function valueAccessor(scope, element) {
|
||||||
required = required || required === '';
|
required = required || required === '';
|
||||||
if (!validator) throw "Validator named '" + validatorName + "' not found.";
|
if (!validator) throw "Validator named '" + validatorName + "' not found.";
|
||||||
function validate(value) {
|
function validate(value) {
|
||||||
|
var force = false;
|
||||||
|
if (isUndefined(value)) {
|
||||||
|
value = element.val();
|
||||||
|
force = true;
|
||||||
|
}
|
||||||
if (element[0].disabled || isString(element.attr('readonly'))) {
|
if (element[0].disabled || isString(element.attr('readonly'))) {
|
||||||
elementError(element, NG_VALIDATION_ERROR, null);
|
elementError(element, NG_VALIDATION_ERROR, null);
|
||||||
invalidWidgets.markValid(element);
|
invalidWidgets.markValid(element);
|
||||||
|
|
@ -3211,8 +3216,8 @@ function valueAccessor(scope, element) {
|
||||||
validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element});
|
validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element});
|
||||||
error = required && !trim(value) ?
|
error = required && !trim(value) ?
|
||||||
"Required" :
|
"Required" :
|
||||||
validator({state:validateScope, scope:{get:validateScope.$get, set:validateScope.$set}}, value);
|
(trim(value) ? validator({state:validateScope, scope:{get:validateScope.$get, set:validateScope.$set}}, value) : null);
|
||||||
if (error !== lastError) {
|
if (error !== lastError || force) {
|
||||||
elementError(element, NG_VALIDATION_ERROR, error);
|
elementError(element, NG_VALIDATION_ERROR, error);
|
||||||
lastError = error;
|
lastError = error;
|
||||||
if (error)
|
if (error)
|
||||||
|
|
@ -3621,14 +3626,12 @@ angularService('$route', function(location, params){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function updateRoute(){
|
function updateRoute(){
|
||||||
console.log('updating route');
|
|
||||||
var childScope;
|
var childScope;
|
||||||
$route.current = null;
|
$route.current = null;
|
||||||
angular.foreach(routes, function(routeParams, route) {
|
angular.foreach(routes, function(routeParams, route) {
|
||||||
if (!childScope) {
|
if (!childScope) {
|
||||||
var pathParams = matcher(location.hashPath, route);
|
var pathParams = matcher(location.hashPath, route);
|
||||||
if (pathParams) {
|
if (pathParams) {
|
||||||
console.log('new route', routeParams.template, location.hashPath, location.hash);
|
|
||||||
childScope = angular.scope(parentScope);
|
childScope = angular.scope(parentScope);
|
||||||
$route.current = angular.extend({}, routeParams, {
|
$route.current = angular.extend({}, routeParams, {
|
||||||
scope: childScope,
|
scope: childScope,
|
||||||
|
|
|
||||||
|
|
@ -165,14 +165,12 @@ angularService('$route', function(location, params){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function updateRoute(){
|
function updateRoute(){
|
||||||
console.log('updating route');
|
|
||||||
var childScope;
|
var childScope;
|
||||||
$route.current = null;
|
$route.current = null;
|
||||||
angular.foreach(routes, function(routeParams, route) {
|
angular.foreach(routes, function(routeParams, route) {
|
||||||
if (!childScope) {
|
if (!childScope) {
|
||||||
var pathParams = matcher(location.hashPath, route);
|
var pathParams = matcher(location.hashPath, route);
|
||||||
if (pathParams) {
|
if (pathParams) {
|
||||||
console.log('new route', routeParams.template, location.hashPath, location.hash);
|
|
||||||
childScope = angular.scope(parentScope);
|
childScope = angular.scope(parentScope);
|
||||||
$route.current = angular.extend({}, routeParams, {
|
$route.current = angular.extend({}, routeParams, {
|
||||||
scope: childScope,
|
scope: childScope,
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ foreach({
|
||||||
element.removeClass('ng-input-indicator-wait');
|
element.removeClass('ng-input-indicator-wait');
|
||||||
scope.$invalidWidgets.markValid(element);
|
scope.$invalidWidgets.markValid(element);
|
||||||
}
|
}
|
||||||
element.data('$validate')(input);
|
element.data('$validate')();
|
||||||
scope.$root.$eval();
|
scope.$root.$eval();
|
||||||
});
|
});
|
||||||
} else if (inputState.inFlight) {
|
} else if (inputState.inFlight) {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,11 @@ function valueAccessor(scope, element) {
|
||||||
required = required || required === '';
|
required = required || required === '';
|
||||||
if (!validator) throw "Validator named '" + validatorName + "' not found.";
|
if (!validator) throw "Validator named '" + validatorName + "' not found.";
|
||||||
function validate(value) {
|
function validate(value) {
|
||||||
|
var force = false;
|
||||||
|
if (isUndefined(value)) {
|
||||||
|
value = element.val();
|
||||||
|
force = true;
|
||||||
|
}
|
||||||
if (element[0].disabled || isString(element.attr('readonly'))) {
|
if (element[0].disabled || isString(element.attr('readonly'))) {
|
||||||
elementError(element, NG_VALIDATION_ERROR, null);
|
elementError(element, NG_VALIDATION_ERROR, null);
|
||||||
invalidWidgets.markValid(element);
|
invalidWidgets.markValid(element);
|
||||||
|
|
@ -36,8 +41,8 @@ function valueAccessor(scope, element) {
|
||||||
validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element});
|
validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element});
|
||||||
error = required && !trim(value) ?
|
error = required && !trim(value) ?
|
||||||
"Required" :
|
"Required" :
|
||||||
validator({state:validateScope, scope:{get:validateScope.$get, set:validateScope.$set}}, value);
|
(trim(value) ? validator({state:validateScope, scope:{get:validateScope.$get, set:validateScope.$set}}, value) : null);
|
||||||
if (error !== lastError) {
|
if (error !== lastError || force) {
|
||||||
elementError(element, NG_VALIDATION_ERROR, error);
|
elementError(element, NG_VALIDATION_ERROR, error);
|
||||||
lastError = error;
|
lastError = error;
|
||||||
if (error)
|
if (error)
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ describe("input widget", function(){
|
||||||
expect(scope.$element[0].checked).toEqual(false);
|
expect(scope.$element[0].checked).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should process ng-validation", function(){
|
it("should process ng-validate", function(){
|
||||||
compile('<input type="text" name="price" value="abc" ng-validate="number"/>');
|
compile('<input type="text" name="price" value="abc" ng-validate="number"/>');
|
||||||
expect(element.hasClass('ng-validation-error')).toBeTruthy();
|
expect(element.hasClass('ng-validation-error')).toBeTruthy();
|
||||||
expect(element.attr('ng-validation-error')).toEqual('Not a number');
|
expect(element.attr('ng-validation-error')).toEqual('Not a number');
|
||||||
|
|
@ -76,6 +76,19 @@ describe("input widget", function(){
|
||||||
expect(element.attr('ng-validation-error')).toEqual('Not a number');
|
expect(element.attr('ng-validation-error')).toEqual('Not a number');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not call validator if undefinde/empty", function(){
|
||||||
|
var lastValue = "NOT_CALLED";
|
||||||
|
angularValidator.myValidator = function(value){lastValue = value;};
|
||||||
|
compile('<input type="text" name="url" ng-validate="myValidator"/>');
|
||||||
|
expect(lastValue).toEqual("NOT_CALLED");
|
||||||
|
|
||||||
|
scope.url = 'http://server';
|
||||||
|
scope.$eval();
|
||||||
|
expect(lastValue).toEqual("http://server");
|
||||||
|
|
||||||
|
delete angularValidator.myValidator;
|
||||||
|
});
|
||||||
|
|
||||||
it("should ignore disabled widgets", function(){
|
it("should ignore disabled widgets", function(){
|
||||||
compile('<input type="text" name="price" ng-required disabled/>');
|
compile('<input type="text" name="price" ng-required disabled/>');
|
||||||
expect(element.hasClass('ng-validation-error')).toBeFalsy();
|
expect(element.hasClass('ng-validation-error')).toBeFalsy();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue