angular-validation icon indicating copy to clipboard operation
angular-validation copied to clipboard

Show default or custom success message only if directive is available in the element.

Open jeevasusej opened this issue 9 years ago • 15 comments

Added a condition that Show default or custom success message only if directive is available in the element.

The following code is added in the validFunc

 var successMessage = validation + 'SuccessMessage';
            var messageToShow = (attrs[successMessage] !== null && attrs[successMessage] !== undefined) ? (validMessage || $validationProvider.getDefaultMsg(validation).success) : "";

jeevasusej avatar Oct 19 '16 12:10 jeevasusej

Thanks for the PR @jeevasusej

can you share one use case example what this function actually does?

hueitan avatar Oct 19 '16 15:10 hueitan

Now the directive will show default success message for all the input element which is validated.

The following scenarios will be done

  1. Suppose user didn't mention the success message directive, then no success message will be displayed for the valid input.
  2. If user mention only the success message directive not the message means (for example, required-success-message), then default success message which is mentioned in the plugin will be used.
  3. If user mention the success message directive and the message means (for example, required-success-message="Thanks for the valid data"), then the custom message will be displayed.

jeevasusej avatar Oct 20 '16 05:10 jeevasusej

This is a nice trick, but I suggest people define the message in rule, not set the message in the directive required-success-message

what you can do? Doc. you can config show or hide the success message globally $validationProvider.showSuccessMessage = false;

is this useful in your case?

hueitan avatar Oct 20 '16 08:10 hueitan

Sorry. This will not be helpful.

$validationProvider.showSuccessMessage = false;

The above option will hide the message globally.

But in some scenarios like follow

  1. Some pages, I may need success message.
  2. Some pages, I may not need success message.

In the above case, I need to get the $validationProvider provider and change based on the page requirement.

So that I have added a condition for this.

  1. If user needs, user can mention the directive
  2. If user needs custom message, user can mention
  3. If user doesn't need for particular page, user no need to mention the attribute
  4. If user don't want for the whole application, user can set

$validationProvider.showSuccessMessage = false;

jeevasusej avatar Oct 20 '16 08:10 jeevasusej

Will this idea give more option for the user?

jeevasusej avatar Oct 20 '16 08:10 jeevasusej

I'm sorry that.

again

I suggest people define the message in rule, not set the message in the directive required-success-message

There is one more trick : set the message to be empty String, so it won't show the success messsage.


I will bump an issue about allowing specific Form to show/hide Success/Error message instead of globally. https://github.com/huei90/angular-validation/issues/249

what do you see?

hueitan avatar Oct 20 '16 08:10 hueitan

set the message to be empty String, so it won't show the success messsage.

For this while I am code, each time, I need to send the empty span tags. So this makes me to add more code.

I will bump an issue about allowing specific Form to show/hide Success/Error message instead of globally.

If we do like this, then each time I need to set the show/hide property for each form in all the pages.

Since I am too lazy, If I forget the directive (or attribute that is required-success-message or number-success-message) to mention in the element, then the success message won't be displayed.

So

  1. I don't need to do extra code to hide.
  2. I don't need to have the empty code with required-success-message, which is not used by the user and not displayed in the browser.

Will this valuable?

jeevasusej avatar Oct 20 '16 09:10 jeevasusej

Do you prefer

set every input it's own validation directive message 

instead of

each time I need to set the show/hide property for each form in all the pages.

?

hueitan avatar Oct 20 '16 09:10 hueitan

Sorry, I cannot understand.

jeevasusej avatar Oct 20 '16 09:10 jeevasusej

you set the validation directive message (e.g. required-success-message ) for every input fields?

hueitan avatar Oct 20 '16 09:10 hueitan

set every input it's own validation directive message

For error validation directive message, there is no problem. This is the reason we are using this plugin.

But, For success validation directive message, I am no sure that we will need or not in all the case.

If I don't need, why do need to mention as directive in the element or why do I need to have the option for each page?

jeevasusej avatar Oct 20 '16 09:10 jeevasusej

unfortunately, there is no better solution in the current version.

The creation of the validation directive message is just a quick hand to overwrite the global message. That's the reason why I suggest people define their message in the config.

The solution I would suggest now

  1. setting the global hide success message
  2. setting the message to be empty string

I have no idea which solution will be the best to specific which message to show and hide.

hueitan avatar Oct 20 '16 09:10 hueitan

Hi, I create an issue about it. https://github.com/huei90/angular-validation/issues/250

Feel free to add some points on it.

hueitan avatar Oct 20 '16 09:10 hueitan

Thanks for the info and thanks for your patience towards me.

setting the message to be empty string This is what doesn't make sense for me.

Please see the following code.

<input type="text" class="form-control"
                               validator="required" name="Firstname"
                               required-error-message="User information is lacking in the field"
                               required-success-message="&lt;span&gt;&lt;&#47;span&gt;"
                               ng-model="user.firstName" id="Firstname" placeholder="Full name...">

The above is the code using existing code. I need to set the empty string in that.

After adding the following code in the validFunc

var successMessage = validation + 'SuccessMessage';
            var messageToShow = (attrs[successMessage] !== null && attrs[successMessage] !== undefined) ? (validMessage || $validationProvider.getDefaultMsg(validation).success) : "";

My Code will be

<input type="text" class="form-control"
                               validator="required" name="Firstname"
                               required-error-message="User information is lacking in the field"
                               ng-model="user.firstName" id="Firstname" placeholder="Full name...">
  • So in my scenario, in this page itself, I don't want the success message. If I don't want, then why should I mention in the element

If I want to add default success message,

<input type="text" class="form-control"
                               validator="required" name="Firstname"
                               required-error-message="User information is lacking in the field"
                               required-success-message
                               ng-model="user.firstName" id="Firstname" placeholder="Full name...">

else

<input type="text" class="form-control"
                               validator="required" name="Firstname"
                               required-error-message="User information is lacking in the field"
                               required-success-message="Thanks for your info"
                               ng-model="user.firstName" id="Firstname" placeholder="Full name...">
  • Setting globally will hide globally. I don't to hide globally.

jeevasusej avatar Oct 20 '16 09:10 jeevasusej

Thank you for describing the issue, I will think about it and give the solution in #250

You can now fork the branch and edit the validFunc until we got something improvements 😄

hueitan avatar Oct 20 '16 09:10 hueitan