implementation of custom validation on click of Save & Submit Button in angularjs -
i new angularjs , need develop single page application. have requirement of implementation of angular validation.
i have 10 fields(input, select , listbox) on page , 2 buttons(save , submit). when click on save 6 fields(just example) should have valid values , when click on submit button- 8 fields should checked.
but problem is. if used form tag on page how implement these validation.
your appreciated.
write code in controller
obj.haserrorwithsubmit = function (form, field, validation) { if (validation) { return ($scope.submitted && form[field].$error[validation]); } return (form[field].$dirty && form[field].$invalid) || ($scope.submitted && form[field].$invalid); }; obj.haserrorwithsave = function (form, field, validation) { if (validation) { return ($scope.save && form[field].$error[validation]); } return (form[field].$dirty && form[field].$invalid) || ($scope.submitted ``&& form[field].$invalid); };
write in html
ng-class="{'classname':obj.haserrorwithsubmit(formname,'fieldname','validationtype')}">
i.e
ng-class="{'classname':obj.haserrorwithsubmit(myform,'textfield1','required')}"> ng-class="{'classname':obj.haserrorwithsave (myform,'textfield2','required')}">
classname css class makes border red
by clicking on submit button make $scope.submitted =true clicking on save button make $scope.save =true
Comments
Post a Comment