Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  50] [ 2]  / answers: 1 / hits: 19698  / 11 Years ago, tue, january 7, 2014, 12:00:00

I am trying to validate < input type = number > by using input [number]
directive of module ng of angularjs.



When using an input of type number, with the max (or min) attribute set to number such as



<input type=number min=20 max=40>



it works fine , but I my min and max data are coming data dynamically using ng-repeat such as



<input type=number min=configRow.valueStart max=configRow.valueEnd> ,
then it is not working .



I know that min and max only accept number and I am not much good in writing directives for that , Please help me any such directory or any suggestions would be appreciated.


More From » angularjs

 Answers
109

min and max are expecting a value. So, this should work:



<input type=number min={{configRow.valueStart}} max={{configRow.valueEnd}}>


Here is a plunker showing a demo. (this is just a modification of the documentation demo).



At the moment, the source for these attributes looks like below. So, you can see that a value is expected that is then cast to a float with parseFloat. So interpolating the model property {{}} to a value is required.



src/ng/directive/input.js



if (attr.min) {
var minValidator = function(value) {
var min = parseFloat(attr.min);
return validate(ctrl, 'min', ctrl.$isEmpty(value) || value >= min, value);
};

ctrl.$parsers.push(minValidator);
ctrl.$formatters.push(minValidator);
}

if (attr.max) {
var maxValidator = function(value) {
var max = parseFloat(attr.max);
return validate(ctrl, 'max', ctrl.$isEmpty(value) || value <= max, value);
};

ctrl.$parsers.push(maxValidator);
ctrl.$formatters.push(maxValidator);
}

[#73333] Sunday, January 5, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliano

Total Points: 381
Total Questions: 109
Total Answers: 93

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
emiliano questions
;