angular-auto-validate
angular-auto-validate copied to clipboard
How to Replace Variables in Error Messages
I have a custom validation directive which checks for unique name in the given list.
var validator = function(value){
//Add the logic to check the uniqueness
if(true){
ctrl.$setValidity('uniqueInTheList', true);
return value;
}else{
ctrl.$setValidity('uniqueInTheList', false);
return undefined;
}
};
I am able to validate the input element, but I want to replace the message variables in the message key.
My error Message Key is {0} should be unique
When ever my field gets validated, I get message like should be unique.
Is there a way to say that Key Pair should be unique,Host Name should be unique
one way to do it is to do custom messages via http://jonsamwell.github.io/angular-auto-validate/#overriding_error_message like so
uniqueInTheList-err-type="uniqueInTheListMessageForKeyPair"
I think that is currently the best approach
@icornejo Thanks for the reply. I am already using it, I am looking for a better approach. Thanks for the time.
@jonsamwell Can we figure out a better way to fix it. Let me know if you have any design. I can work on it and create a pull request
@jagadeshpaladugula I'm planning to look into adding this functionality this week.
Any ideas on how to make this work with values that are passed into the error message? In the exact same scenario above, I want to show the value that is invalid.
For example, instead of saying "Username already exists" I want to say "Username {typed_username} already exists" where what the user typed (and we validated with server query) is shown so that there is no doubt.
+1
Sorry all been really really really busy at work but I will get around to this next week
@dhiraj would you just want to use the value from the ng-model that is on the control?
@jonsamwell Well yeah, that's what I came to the issue with. Just that would solve my particular problem.
+1!
Has this functionality been added yet? There is no mention of it in the latest released version.