i am trying to add a custom validation field to the validator firld using the addClassRules
That's just not possible...
jQuery.validator.addClassRules("checkrequired", {
rules: {
required: true
},
tooltip_options: { // <- totally invalid option
'_all_': {
placement: 'bottom'
}
}
});
The addClassRules()
method is simply meant for making compound rules and assigning the new compound rule to a class
name.
Description: Add a compound class method – useful to refactor common combinations of rules into a single class.
You can only put existing rules/methods into the addClassRules()
method, not the object literal from an entirely different plugin.
If you're trying to create a new validation rule from scratch, you'd use the addMethod()
method.
"i need to add a placeholder as i want to show the error in placeholder"
You've really not explained this very well at all, but I don't think this has anything to do with creating a new validation rule.
There are various options and functions you can use to over-ride the default behavior. Please improve your question so we can help you.
If you're trying to integrate a tooltip plugin with jQuery Validate, that is much more involved. See this for an example using the ToolTipster plugin.
How to display messages from jQuery Validate plugin inside of Tooltipster tooltips?
However, be aware that every tooltip plugin is going to have a slightly different solution depending on its capabilities.
"all i want to either use the addClassRules
or addMethod
to make it work"
You can't.
Those two methods are specific to creating new methods (validation rules), they have nothing to do with the behavior of message placement. Again, review the available configuration options.