0

我有一个购物车表单,其中有一个优惠券代码字段,用户在其中输入优惠券,我验证它是否为空白。在同一个表单上,我还有一个单独的按钮,它将触发条纹弹出信用卡支付框。当我完成信用卡付款时,优惠券代码文本框会触发它不应该的“必填字段”错误。

 <form action="/cart/" method="post" id="promotion-form" name="submit_promotion">
      <textarea placeholder="Enter promotional code" class="promotional-box" name="code" id="code"></textarea> 
      <input type="hidden" value="1" name="plan_id" id="plan_id">
     <button class="btn-apply pull-right" name="promotion-submit" type="submit">Apply</button>
                        </form>

jQuery

$('#promotion-form').validate(
        {
            rules: {
                code: {
                    minlength: 5,
                    required: true
                }

            },
            highlight: function(element) {
                $(element).closest('.control-group').removeClass('success').addClass('error');
            },
            success: function(element) {

            }
        });
4

1 回答 1

0

$("#promotion-form").click(function(){ $("input.code").each(function(){ $(this).rules("add", { required: true, messages: { required: "需要代码。" } } );
}); });

于 2013-06-28T20:28:01.947 回答