【问题标题】:passing multiple fileds for ajax validation with jquery validation engine使用 jquery 验证引擎传递多个字段以进行 ajax 验证
【发布时间】:2015-01-31 14:39:55
【问题描述】:

我正在使用 jquery 验证引擎来验证表单输入。它工作正常。 我有一种情况,我向用户询问国家和邮政编码,我需要验证国家和邮政编码的组合是否有效。

单独验证字段的代码可以正常工作,如下所示:

<p class="mediumlargefont add_margin_top">Please confirm your country:</p>
<input onclick="$('#postcode').validationEngine('showPrompt', 'Please select your country', 'load')"
    class="validate[required, custom[onlyLetterSp], maxSize[30], ajax[ajaxNameCallCountry]]" 
    type="text" name="country" id="autocomplete" value="[% IF country; country; END %]"/>
</div>
<div>
    <p class="mediumlargefont add_margin_top">Please enter your postcode:</p>
    <input maxlength="10" size="22"  
    onclick="$('#postcode').validationEngine('showPrompt', 'Please enter the postcode of your current location', 'load')"
    class="validate[condRequired[country], custom[onlyLetterNumberSpHy], maxSize[10], ajax[ajaxNameCallPostcode]]" 
    type="text" name="postcode" id="postcode" data-prompt-position="centerRight"/>
</ul>

我想知道的是,当我验证邮政编码时,有没有办法通过 ajax 调用将国家/地区输入的当前值传递给后端?这将允许我验证组合。

顺便说一句,验证引擎的 JS 如下所示:

$(document).ready( function(){
    $("#postcodeForm").validationEngine('attach', 'autoHidePrompt', {
        scroll: "false",
        ajaxFormValidation : "true"
    });
});

【问题讨论】:

    标签: jquery-validation-engine


    【解决方案1】:

    当然,10 分钟后我找到了答案。希望对其他人有所帮助。

    在 ajax 选择器的定义中添加 extraDataDynamic

    例如,

    "ajaxUserCall": {
        "url": "ajaxValidateFieldUser",
        "extraData": "name=eric",
        "extraDataDynamic": ['#user_id', '#user_email'],
        "alertText": "* This user is already taken",
        "alertTextOk": "All good!",
        "alertTextLoad": "* Validating, please wait"
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多