Validate match only if field is required?
Closed this issue · 1 comments
Hi,
Hopefully a quick question.
I only want to validate for a match if my first input has a value. Does angular-validation-match have a way to conditionally validate matches? Maybe something similar to ng-required?
<input name="txtSearchTitle" class="form-control" ng-model="SearchTitle" />
<input name="txtConfirmNewTitle" class="form-control" ng-model="SearchTitleConfirmation" ng-required="SearchTitle" match="SearchTitle"/>
<p class="help-block" ng-show="frmJobList.txtConfirmNewTitle.$error.required && submitted">Please enter a value</p>
<p class="help-block" ng-show="frmJobList.txtConfirmNewTitle.$error.match && submitted">Confirmation must match entered search title.</p>
No, there is not a way to conditionally validate (that I can think of) other than adding and removing the input using ng-if
(having one input with match that is shown only when the original field is valid, and another without match that is shown when the original field is invalid.)
I can see adding a separate optional attribute match-if="expression"
which will validate matching when the value of the expression is true
and not perform validation when it is false
, it would default to true
to the attribute is not provided.