Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jeevasusej
Copy link

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) : "";

@hueitan
Copy link
Owner

hueitan commented Oct 19, 2016

Thanks for the PR @jeevasusej

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

@jeevasusej
Copy link
Author

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.

@hueitan
Copy link
Owner

hueitan commented Oct 20, 2016

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?

@jeevasusej
Copy link
Author

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
Copy link
Author

Will this idea give more option for the user?

@hueitan
Copy link
Owner

hueitan commented Oct 20, 2016

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. #249

what do you see?

@jeevasusej
Copy link
Author

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?

@hueitan
Copy link
Owner

hueitan commented Oct 20, 2016

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.

?

@jeevasusej
Copy link
Author

Sorry, I cannot understand.

@hueitan
Copy link
Owner

hueitan commented Oct 20, 2016

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

@jeevasusej
Copy link
Author

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?

@hueitan
Copy link
Owner

hueitan commented Oct 20, 2016

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
Copy link
Owner

hueitan commented Oct 20, 2016

Hi, I create an issue about it. #250

Feel free to add some points on it.

@jeevasusej
Copy link
Author

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.

@hueitan
Copy link
Owner

hueitan commented Oct 20, 2016

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants