Parsley JS 2.x-如何验证隐藏字段? [英] Parsley JS 2.x - how do you validate hidden fields?

查看:42
本文介绍了Parsley JS 2.x-如何验证隐藏字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证隐藏字段,因此本质上我想从香菜的排除表单元素列表中删除 input [type = hidden] .我已经尝试在parsley的选项中显式设置排除的元素,但是隐藏字段仍未通过验证.例如:

I would like to validate hidden fields, so essentially I want to remove input[type=hidden] from parsley's list of excluded form elements. I've tried explicitly setting excluded elements in parsley's options, but hidden fields are still not validated. E.g:

$(element).parsley({
    excluded: 'input[type=button], input[type=submit]'
});

关于如何实现这一目标的任何想法,或者我做错了什么?

Any thoughts on how to accomplish this, or what I'm doing wrong?

推荐答案

我猜这是一个错误.

采用此形式:

<form method="post" id="myForm">
    <input type="text" name="field1" value="" class="required" />
    <input type="hidden" name="hiddeninput" value="" class="required" />
    <input type="submit" value="Go">
</form>

使用以下JavaScript,即使我们告诉Parsley验证隐藏字段,也无法正常工作

With the following javascript, even though we tell Parsley to validate hidden fields, it does not work:

$("#myForm").parsley({
    excluded: 'input[type=button], input[type=submit], input[type=reset]',
    inputs: 'input, textarea, select, input[type=hidden], :hidden',
});

但是,如果将其定义为全局配置,它确实可以工作

However, if you define this as a global configuration, it does work

window.ParsleyConfig = {
    excluded: 'input[type=button], input[type=submit], input[type=reset]',
    inputs: 'input, textarea, select, input[type=hidden], :hidden',
};

$("#myForm").parsley();

这篇关于Parsley JS 2.x-如何验证隐藏字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆