I have a form that, if false, forces the text to be checked using the ng-required directive. If the checkbox is set correctly, the field is hidden, and ng-required is set to false.
The problem is that I also have a regex for the validation specified on the input, as well as using the ng-pattern angular directive. The problem I am facing is that if the user fills out an invalid phone number, he checks the checkbox to deactivate this input (and therefore does not need further verification), the form does not allow submission, since it is invalid based on ng -pattern.
I tried to solve this problem by adding the ng-change function to set the input model to null, however the ng-template and, therefore, the field is still set as invalid in the original flag set to false. If, however, I clear the checkbox by setting everything back to the bootstrap form, then check the box again, the form is valid and can file. I'm not sure what I am missing. Here is the ng-change code that I still have:
var phoneNumberRegex = /^\(?(\d{3})\)?[ .-]?(\d{3})[ .-]?(\d{4})$/; $scope.phoneNumberPattern = phoneNumberRegex; $scope.removeValidation = function() { if ($scope.cell._newUser === false) { $scope.request._number = ''; $scope.phoneNumberPattern = /[0-9a-zA-Z]?/; } else { $scope.phoneNumberPattern = phoneNumberRegex; } };
angularjs angularjs-directive angularjs-ng-change
Brian Sep 19 '13 at 16:33 2013-09-19 16:33
source share