diff --git a/src/widget/input.js b/src/widget/input.js index 3f25f09fe8ba..8087791815d6 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -570,19 +570,32 @@ angularInputType('radio', function(inputElement) { function numericRegexpInputType(regexp, error) { return ['$element', function(inputElement) { - var widget = this, - min = 1 * (inputElement.attr('min') || Number.MIN_VALUE), - max = 1 * (inputElement.attr('max') || Number.MAX_VALUE); + var widget = this; + var modelScope = inputElement.scope(); + + watchElementProperty(modelScope, widget, 'min', inputElement); + watchElementProperty(modelScope, widget, 'max', inputElement); widget.$on('$validate', function(event){ var value = widget.$viewValue, filled = value && trim(value) != '', - valid = isString(value) && value.match(regexp); + valid = !!(isString(value) && value.match(regexp)), + isInvalid = filled && !valid; + if (widget.$error[error] != isInvalid){ + widget.$emit(isInvalid ? '$invalid' : '$valid', error); + } - widget.$emit(!filled || valid ? "$valid" : "$invalid", error); filled && (value = 1 * value); - widget.$emit(valid && value < min ? "$invalid" : "$valid", "MIN"); - widget.$emit(valid && value > max ? "$invalid" : "$valid", "MAX"); + + var isToLow = filled && valid && widget.$min && trim(widget.$min) != '' && value < (1 * widget.$min), + isToHigh = filled && valid && widget.$max && trim(widget.$max) != '' && value > (1 * widget.$max); + + if (widget.$error.MIN != isToLow){ + widget.$emit(isToLow ? '$invalid' : '$valid', 'MIN'); + } + if (widget.$error.MAX != isToHigh){ + widget.$emit(isToHigh ? '$invalid' : '$valid', 'MAX'); + } }); widget.$parseView = function() { diff --git a/test/widget/inputSpec.js b/test/widget/inputSpec.js index dfbc506aaf6a..8b6db894eafa 100644 --- a/test/widget/inputSpec.js +++ b/test/widget/inputSpec.js @@ -572,16 +572,29 @@ describe('widget: input', function() { itShouldVerify('integer', - [null, '', '1', '12', '-4', '+13'], + [null, undefined, '', '1', '12', '-4', '+13'], ['x', '12b', '-6', '101', '1.', '1.2'], {min:-5, max:100}); itShouldVerify('integer', - [null, '', '0', '1'], + [null, undefined, '', '0', '1'], ['-1', '2'], {min:0, max:1}); + itShouldVerify('integer', + [], + [null, '', undefined], + {required:true}); + + itShouldVerify('integer', + [null, undefined, '', '0', '1'], + ['-2','2'], + {min: "{{min_value}}", max:"{{max_value}}"}, function(scope){ + scope.min_value = "-1"; + scope.max_value = "1"; + }); + itShouldVerify('text with inlined pattern constraint', ['', '000-00-0000', '123-45-6789'], pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy