angular-auto-validate icon indicating copy to clipboard operation
angular-auto-validate copied to clipboard

How to Replace Variables in Error Messages

Open jagadeshpaladugula opened this issue 10 years ago • 11 comments
trafficstars

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

jagadeshpaladugula avatar May 27 '15 08:05 jagadeshpaladugula

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"

lcornejo avatar May 29 '15 21:05 lcornejo

I think that is currently the best approach

jonsamwell avatar May 29 '15 22:05 jonsamwell

@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 avatar Jun 02 '15 18:06 jagadeshpaladugula

@jagadeshpaladugula I'm planning to look into adding this functionality this week.

jonsamwell avatar Sep 02 '15 10:09 jonsamwell

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.

dhiraj avatar Sep 18 '15 11:09 dhiraj

+1

LeleDev avatar Sep 30 '15 10:09 LeleDev

Sorry all been really really really busy at work but I will get around to this next week

jonsamwell avatar Sep 30 '15 11:09 jonsamwell

@dhiraj would you just want to use the value from the ng-model that is on the control?

jonsamwell avatar Sep 30 '15 11:09 jonsamwell

@jonsamwell Well yeah, that's what I came to the issue with. Just that would solve my particular problem.

dhiraj avatar Sep 30 '15 12:09 dhiraj

+1!

3ynm avatar Oct 28 '15 07:10 3ynm

Has this functionality been added yet? There is no mention of it in the latest released version.

osbeug001 avatar Oct 17 '16 13:10 osbeug001