diff options
| -rw-r--r-- | src/validators.js | 2 | ||||
| -rw-r--r-- | src/widgets.js | 16 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 15 |
3 files changed, 22 insertions, 11 deletions
diff --git a/src/validators.js b/src/validators.js index 81d40264..5c7fc952 100644 --- a/src/validators.js +++ b/src/validators.js @@ -1,5 +1,5 @@ foreach({ - 'noop': noop, + 'noop': function() { return null; }, 'regexp': function(value, regexp, msg) { if (!value.match(regexp)) { diff --git a/src/widgets.js b/src/widgets.js index 5df92de0..30a4a088 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -15,9 +15,9 @@ function modelAccessor(scope, element) { function modelFormattedAccessor(scope, element) { var accessor = modelAccessor(scope, element), - farmatterName = element.attr('ng-format') || NOOP, - formatter = angularFormatter(farmatterName); - if (!formatter) throw "Formatter named '" + farmatterName + "' not found."; + formatterName = element.attr('ng-format') || NOOP, + formatter = angularFormatter(formatterName); + if (!formatter) throw "Formatter named '" + formatterName + "' not found."; return { get: function() { return formatter.format(accessor.get()); @@ -36,12 +36,12 @@ function valueAccessor(scope, element) { var validatorName = element.attr('ng-validate') || NOOP, validator = compileValidator(validatorName), requiredExpr = element.attr('ng-required'), - farmatterName = element.attr('ng-format') || NOOP, - formatter = angularFormatter(farmatterName), + formatterName = element.attr('ng-format') || NOOP, + formatter = angularFormatter(formatterName), format, parse, lastError, required; invalidWidgets = scope.$invalidWidgets || {markValid:noop, markInvalid:noop}; if (!validator) throw "Validator named '" + validatorName + "' not found."; - if (!formatter) throw "Formatter named '" + farmatterName + "' not found."; + if (!formatter) throw "Formatter named '" + formatterName + "' not found."; format = formatter.format; parse = formatter.parse; if (requiredExpr) { @@ -86,8 +86,8 @@ function valueAccessor(scope, element) { var error, validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element}); error = required && !value ? - "Required" : - (value ? validator(validateScope, value) : null); + 'Required' : + value ? validator(validateScope, value) : null; elementError(element, NG_VALIDATION_ERROR, error); lastError = error; if (error) { diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 40f52b8e..a053090e 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -43,7 +43,7 @@ describe("widget", function(){ describe("ng-format", function(){ - it("should farmat text", function(){ + it("should format text", function(){ compile('<input type="Text" name="list" value="a,b,c" ng-format="list"/>'); expect(scope.$get('list')).toEqual(['a', 'b', 'c']); @@ -178,7 +178,18 @@ describe("widget", function(){ expect(element.attr('ng-validation-error')).toEqual('Not a number'); }); - it("should not call validator if undefinde/empty", function(){ + it('should not blow up for validation with bound attributes', function() { + compile('<input type="text" name="price" boo="{{abc}}" ng-required/>'); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-validation-error')).toEqual('Required'); + + scope.$set('price', '123'); + scope.$eval(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + }); + + it("should not call validator if undefined/empty", function(){ var lastValue = "NOT_CALLED"; angularValidator.myValidator = function(value){lastValue = value;}; compile('<input type="text" name="url" ng-validate="myValidator"/>'); |
