0

i am trying to add a custom validation field to the validator firld using the addClassRules but it is not working..

jQuery.validator.addClassRules("checkrequired", {
      rules: {
        required: true
      },
      tooltip_options: {
        '_all_': {
            placement: 'bottom'
        }
      }
    });

i need to add a placeholder as i want to show the error in the tooltip.

The whole idea is that i want to use this class or addmethod as you suggested for multiple fields which are getting generated from the database, so a message will be common, the field is required.

and all those error message will be appearing in the tooltip, all i want to either use the addClassRules or addMethod to make it work

Sparky
  • 98,165
  • 25
  • 199
  • 285
glenn
  • 25
  • 4
  • *"all i want to either use the `addClassRules` or `addMethod` to make it work"* ~ **you can't** – Sparky Jun 26 '15 at 17:23

1 Answers1

0

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.

Community
  • 1
  • 1
Sparky
  • 98,165
  • 25
  • 199
  • 285