Monday 15 September 2014

Jquery validation get error type -


I am using the jQuery validation plugin. Is there a way to get the type of error from jQuery form validation? For example, validate

  $ ('mform') ({Rule: {Email: {Required: true, maximum length: 40}}, Message: {email: {Required: This is a required field. ", Maximum Length:" Please enter less than 40 characters "}}, Error placement: function (error, element) {error.appendTo (element.parent ());}});  Instead of adding "element.parent ()", I want to place only the error message generated by the "required" error within a "div" on "page" If I can get an error type, eg "Required" or "Maximum length" error, I can write code to do this.  

In the above question it is not mentioned whether the parameter is to be added. So ask again.

Any help is appreciated! Thanks!

Edit: Short answer:

What you are requesting can not be done with this plugin. (This is also a very rare opportunity, where some, which can not be done by default, should also not be done at all.) < P> 1) Write your own custom plugin using this plugin as your starting point.

2) Find a plug-in that already does what you want However, I suspect that the requested option should not normally be done by some people, because one exists, a consistent and uniform user experience means that all error messages are handled in the same way, even if the rule is not affected. .


The basic answer is as follows ...


I think you can do this by using the callback function like error placement Error ...

  Error placement: function (error, element) {if (error.text (). IndexOf ("required")! == -1) {error.insertAfter ( Element); } Other {error.insertBefore (element); However, there are some flaws in this solution because it only exemplifies the  initial  placements to the  initial   It handles long ago all the messages of  label  on the error message will be in the same initial state because the plugin only shows / hides the message  label  after its creation. (It can work well in those situations where there is only one type of message on each field.)  

I do not think anybody will work better because it does not help you in this plugin Was made. (Most people believe that when all the errors of the user are consistently identical, IMO.)

I have given a few hundred answers to this plugin And your first one, which I have encountered, requests to be able to handle a type of error message differently than most, most people only want a more consistent user experience.

No comments:

Post a Comment