I'm trying to create a directive which can be used to reset validation status of multiple input controls in a group, when one of the control's value is changed. Groups are identified by the attribute of the directive set in HTML. Ex: - Both of the From Date and To Date inputs resets the validity state when one of the controls input value is changed by the user
This is what I have so far
JS/Angular
angular.module('myModule').directive('groupedInputs', function () {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, element, attrs, ctrl) {
element.on('change', function () {
// Resetting own validity
scope.$apply(ctrl.$setValidity('server', true));
// Here I need to set the validity of the controls which
// have the `GroupedInputs` directive with the
// same attribute value
});
}
};
});
HTML
<input name="FromDate" type="date" class="form-control" ng-model="model.FromDate" grouped-inputs="FromToDates">
<input name="ToDate" type="date" class="form-control" ng-model="model.ToDate" grouped-inputs="FromToDates">
It can reset the validity of the own input control, but can not access the other input controls with directive and same attribute value. What is the best possible angular way to access the other controls by querying the inputs with the same attribute?