Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need some help. I'm doing some validation on an input element and would like to set a dynamic error message in javascript. I am aware of the following way to do this, but my situation has become somewhat complex. The message itself needs to be dynamic. For example, I may want to show the position within a string (i.e. 9) where there is an invalid character.

some html...

<input type="text" name="firstName" ng-model="data.firstName" validate-directive >

<div ng-show="employmentForm.firstName.$invalid">
    <small class="error" ng-show="form.firstName.$error.err1">invalid</small>
    <small class="error" ng-show="form.firstName.$error.err2">{{something dynamic}}</small>
</div>

some javascript..

.directive('validate-directive', function() {
    ...
    ctrl.$setValidity('err2', false);
    //set a custom message to be shown
}

Any suggestions on how I might approach this?

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.