-
Notifications
You must be signed in to change notification settings - Fork 58
Revalidate Input
Since version UNKNOWN
What if you want to validate one element by changing the value of another element?
If your validation function depends on multiple values / multiple fields you can configure validation for one element and revalidate in the change event of another element.
####Demo Don't select too many entries for the same day. Validation rule is executed when changing text or absence type. You can find a Plunker Demo here
####Requirements
- Validation is created via Directive.
####Code Sample This only work with the Directive for now. #####HTML HTML Code
<input type="text" name="absence_day" ng-model="absence.day"
validation="{{absence.absenceType ? 'required' : ''}}|custom:checkCompleteInputIsValid(absence)"
myValidationGroup="absence" />
<select name="absence_type" ng-model="absence.absenceType"
ng-change="absenceTypeChanged('absence_type', 'absence')"
validation="{{ absence.day && absence.day != '' && absence.day != null ? 'required' : ''}}"
myValidationGroup="absence_{{absence.id}}">
<option></option>
<option ng-repeat="absenceType in absenceTypes" value="{{absenceType.id}}">{{absenceType.description}}</option>
</select>
JavaScript Code
$scope.absenceTypeChanged = function(srcElementName, myValidationGroup) {
$timeout(function() { revalidate(srcElementName, myValidationGroup); }, 1);
};
function revalidate(srcElementName, myValidationGroup) {
var elementsToValidate = $("[myValidationGroup='" + myValidationGroup + "']");
elementsToValidate.each(function (index) {
var element = $(this)[0];
if (element.name != srcElementName)
$scope.$broadcast('angularValidation.revalidate', element.name);
});
}
####Revalidate
#####Trigger event
You can trigger the validation of an element by calling $scope.$broadcast('angularValidation.revalidate', ELEMENTNAME);
, and giving the name of the element to revalidate as the second parameter.
Contents
- Angular-Validation Wiki
- Installation
- Demo
- Code Samples
- Functionalities
- Custom Validations
- Properties & Options
- Validators
- Tests
- Misc