如何使用jquery验证Enginejs对可折叠内容块进行验证

时间:2013-07-17 10:20:29

标签: jquery-mobile cordova-2.0.0 jquery-validation-engine

我创建了可折叠的内容,其中包含一些字段,并且我已经使用了 jquery.validationEngine.js 进行验证。问题是当collapsible为true时它不显示验证选项但是如果为false它可以正常工作我想要的是如果可折叠内容中有错误,它应该设置为可折叠为false。

以下是html页面的代码:

<div data-role="collapsible" id='collapsible_2' data-theme="b" data-content-theme="c" style="padding-bottom: 10px">
  <h3>Contact Information</h3>
  <p align="left" style="margin-bottom: 2px"><font color="#3C6FA1"><b>EMAIL ADDRESS</b></font></p>
   <hr>
  <input class="validate[required] text-input" id="email_id" name="emailId" type="text" placeholder="name@sample.com" >
  <p align="left" style="margin-bottom: 2px"><font color="#3C6FA1"><b>PHONE NUMBER</b></font></p>
   <hr>
  <input class="validate[required] text-input" id="main" name="main" type="number" min="0" max="9" maxlength="10" placeholder="Main" >
  <input class="validate[required] text-input" id="mobile" name="mobile" type="text" placeholder="Mobile" >
  <p align="left" style="margin-bottom: 2px"><font color="#3C6FA1"><b>FAX NUMBER</b></font></p>
   <hr>
  <input class="validate[required] text-input"id="fax" name="fax" type="text" placeholder="Fax" >
  <p align="left" style="margin-bottom: 2px"><font color="#3C6FA1"><b>WEBSITE</b></font></p>
   <hr>
  <input class="validate[required] text-input" id="website" name="website" type="text" placeholder="Website" >
  <p align="left" style="margin-bottom: 2px"><font color="#3C6FA1"><b>ADDRESS</b></font></p>
   <hr>
  <input class="validate[required] text-input" id="street_address" name="street_address" type="text" placeholder="Street Address">
  <input class="validate[required] text-input" id="city" name="city" type="text" placeholder="City">
  <input class="validate[required] text-input" id="Region" name="Region" type="text" placeholder="Region">
  <input class="validate[required] text-input" id="postal_code" name="postal_code" type="text" placeholder="Postal Code">
  <select name="select-choice-c" id="select-choice-c" data-native-menu="false" data-theme="a">
    <option>Select Country</option>
    <option value="standard">India</option>
    <option value="rush">Australia</option>
    <option value="express">England</option>
    <option value="overnight">SriLanka</option>
  </select>
</div>

这是我用过的java脚本:

jQuery(document).ready( function() {
 // binds form submission and fields to the validation engine
 jQuery("#formID").validationEngine();
});

这是我用于设计和验证的js和css文件:

<head>
  <link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
  <link rel="stylesheet" href="css/template.css" type="text/css"/>
  <script src="js/jquery.js" type="text/javascript"></script>
  <script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
  <script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
  <link rel="stylesheet" href="contactcss/jquery.mobile-1.3.1.min.css"/>
  <script src="js/jquery.mobile-1.3.1.min.js"></script>
  <script type="text/javascript" charset="utf-8" src="js/cordova-2.7.0.js"></script>
</head>

1 个答案:

答案 0 :(得分:0)

刚刚对jquery.validationEngine.js文件进行了一些更改,如下所示 从:

if (!options.validateNonVisibleFields && (field.is(":hidden") && !options.prettySelect || field.parent().is(":hidden")))
            return false;

要:

if (!options.validateNonVisibleFields && (field.is(":hidden") && !options.prettySelect || field.parent().is(":hidden")))
            return true;

和 来自:

validateNonVisibleFields: false,  lineNo:2008

要:

validateNonVisibleFields: true,