JQuery验证引擎,用于动态添加隐藏的输入字段 [英] JQuery Validation Engine for dynamically added hidden input fields

查看:102
本文介绍了JQuery验证引擎,用于动态添加隐藏的输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JQuery Validation Engine插件来查看动态添加的隐藏输入字段。

I want to use the JQuery Validation Engine plugin to look over dynamically added hidden input fields.

当表单中至少有一个字段必须存在提交。

At least one of this fields has to be there, when the form is submitted.

它尝试使用groupRequired Validator实现此目的

It tried to achieve this with the groupRequired Validator

http://posabsolute.github.com/jQuery-Validation-Engine/#validators/grouprequired

<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
                     <script>
                    $(document).ready(function(){
                        $("#tagform").validationEngine();
                       });
                    </script>
        <form id="tagform">
               <input type="hidden" name="tags" id="tags-input" />
                    <input type="hidden" name="inc" value="locate">
                    <input type="hidden" class="validate[groupRequired[tagitem]]" name="validation">
                    <br><br>
                    <input type="submit" value="Save Tags">

        </form>

添加的字段如下:

 var formhtml ='<input type="hidden" name="tags[]" class="validate[groupRequired[tagitem]]" id="id'+itemid+'" parenttag="'+parent+'" value="'+itemid+'">';
                $("#tagform").append(formhtml);

目前它根本不检查隐藏的字段。

At the moment it simply doesn't check for the hidden fields.

知道如何解决这个或其他方法吗?

Any idea how to fix this or another approach ?

解决方法

使用简单的javaskript onSubmit函数检查标签的出现次数

Use a simple javaskript onSubmit Function to check occurens of tags

function checkForm(form)
{
var count = $('input[name="tags[]"]').length;
if(count == 0 ) {
   alert("Select at least one tag");       
   return false;
}
alert ("Count " + count)
return true;
}

仍然喜欢使用Jquery验证引擎

Still would love to use Jquery Validation Engine

推荐答案

使用validateNonVisibleFields实例化JQuery验证

Instantiate JQuery Validation with validateNonVisibleFields

   <script>
    $(document).ready(function(){
        $("#formID").validationEngine({validateNonVisibleFields: true,
        updatePromptsPosition:true});

       });
    </script>

您仍然遇到Jquery / Javascript无法获取隐藏字段位置的问题。因此,使用样式可见性:隐藏。

Still you have the problem that Jquery / Javascript can not get a position of a hidden field. So use style visibility:hidden instead.

<input name="hiddenq2" type="text" value="" class="validate[required]" jqtop="500" id="form-validation-field-1" style="visibility: hidden">

您仍然可能需要使用promptPosition选项调整一下,但至少会出现一些问题。

You still might have to adjust a little bit with the promptPosition options but at least there is something showing up.

这篇关于JQuery验证引擎,用于动态添加隐藏的输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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