简体   繁体   English

尝试将自定义验证添加到jquery验证程序插件

[英]trying to add a custom validation to jquery validator plugin

i am trying to add a custom validation field to the validator firld using the addClassRules but it is not working.. 我正在尝试使用addClassRules将自定义验证字段添加到验证器字段,但是它不起作用。

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. 整个想法是我addmethod您建议的那样使用此类或addmethod来建议从数据库中生成多个字段,因此消息很常见,该字段是必需的。

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 并且所有这些错误消息将出现在tooltip ,所有我想使用addClassRulesaddMethod使其工作

i am trying to add a custom validation field to the validator firld using the addClassRules 我正在尝试使用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. addClassRules()方法仅用于制作复合规则并将新的复合规则分配给class名。

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. 您只能将现有规则/方法放入addClassRules()方法中,而不能将完全不同插件中的对象文字放入。

If you're trying to create a new validation rule from scratch, you'd use the addMethod() method . 如果您尝试从头开始创建新的验证规则,则可以使用addMethod()方法


"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. 如果您尝试将工具提示插件与jQuery Validate集成在一起,则涉及的更多。 See this for an example using the ToolTipster plugin. 有关使用ToolTipster插件的示例,请参见此示例。

How to display messages from jQuery Validate plugin inside of Tooltipster tooltips? 如何在Tooltipster工具提示中显示来自jQuery Validate插件的消息?

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" “所有我想使用addClassRulesaddMethod使其工作”

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 . 再次,查看可用的配置选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM