does anyone know how to do conditional maxlength in angularjs, I have found conditional required but not maxlength etc....
for example if maxlength given ...it should validate but if maxlength is 0 or false, it should not....
$scope.validation = {a: {required:true,minlength:5, maxlength:10},
b: {required:false,minlength:0, maxlength:false}}
Html gets created using ng-repeat loop....n now problem is maxlength gets fired everytime...whereas i have disabled it for second input field
<input type="text" name="myName" ng-model="name" ng-minlength='validation.a.minlength' ng-maxlength="validation.a.maxlength" ng-required='validation.a.required' />
<input type="text" name="myName1" ng-model="name1" ng-minlength='validation.b.minlength' ng-maxlength="validation.b.maxlength" ng-required='validation.b.required' />
These parameters seems to work, if you use empty strings as "false" via angular expressions.
<input type="text" name="myName" ng-model="name" ng-minlength='{{validation.a.minlength}}' ng-maxlength="{{validation.a.maxlength}}" ng-required='validation.a.required' />
<input type="text" name="myName1" ng-model="name1" ng-minlength='{{validation.b.minlength}}' ng-maxlength="{{validation.b.maxlength}}" ng-required='validation.b.required' />
$scope.validation = {
a: {required:true, minlength:5, maxlength:10},
b: {required:false, minlength:'', maxlength:''}
}
plunker
plunker for 1.3.2
Now its possible to use 0 and Number.MAX_SAFE_INTEGER to ignore this rules. Or maybe just 999 will be enough :)
b: {required:false, minlength:0, maxlength:Number.MAX_SAFE_INTEGER}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With