Проверка JQuery не запускается для флажков

0

У меня есть форма, где я использую проверку jQuery для проверки с передней стороны.

Большинство проверок работают так, как я этого хочу. Однако для флажков валидация не работает. У меня есть следующие правила и сообщения в моем jQuery проверки

  $('#submitDetails').validate({
    // 1. validation rules.
    rules: {
    ......
    ......
    ......
      custom9: {
        required: true
      },
      custom10:{
          required:true
      },
      custom11: {
        required: true
      }
    },
    // 2. Validation fail messages
    messages: {
      custom9: {
        required: "You can only claim your Plush Rewards once you have received all your items found on your reciept"
      },
      custom10: {
        required: "You must agree to the terms of conditions in order to claim your Plush Rewards Prepaid Visa Gift Card"
      },
      custom11: {
        required: "You must agree to the terms of conditions in order to claim your Plush Rewards Prepaid Visa Gift Card"
      }
    ......
    ......
    ......

Html - это

<div class="ticks">
    <div class="col-xs-12  tick1">
        <input type="checkbox" data-label="Have you received your entire order from Plush?" name="custom9" id="custom9" value="0" class="styled myClass prettyCheckable"><span class="mandatory tick1Mandatory"> * </span>

    </div>
    <!--<div id="error_msg"></div>  -->
    <div class="col-xs-12 tick2">
        <input type="checkbox" data-label="Please tick if you would like to join our mailing list and receive special bonus offers and the latest Plush news" name="custom10" id="custom10" value="1" class="styled myClass prettyCheckable" checked>
    </div>
    <div class="col-xs-12 tick3">
        <input type="checkbox" data-label="I have read and agree to the Terms and Conditions of this promotion and understand the Plush Privacy Policy" name="custom11" id="custom11" value="0" class="styled myClass prettyCheckable"><span class="mandatory tick2Mandatory"> * </span>

    </div>
</div>

Когда нажата кнопка отправки, проверки, связанные с custom9-11, не запускаются.

Теги:
jquery-validate

2 ответа

5
Лучший ответ

Вероятно, несколько лет спустя, но на случай, если кто-то еще столкнется с этой проблемой:

Из разметки я могу сказать, что вы используете плагин prettyCheckable для своих флажков. Возможно ли, что ваши фактические флажки скрыты с помощью prettyCheckable, а плагин Validation игнорирует их?

Если это так, вы можете попробовать исправить это, изменив параметр игнорирования плагина jquery.validate:

    $.validator.setDefaults({ 
        ignore: [] // DON'T IGNORE PLUGIN HIDDEN SELECTS, CHECKBOXES AND RADIOS!!!
    });
  • 0
    Вы сэкономили мне кучу времени. Спасибо!
1

Пример HTML для проверки флажка

<label for="terms">terms : </label>
<input type="checkbox" name="terms[]" value="your value" id="terms">
  • укажите имя флажка с квадратными скобками.
  • Предоставьте значение флажку обязательным.

Код Jquery

rules: {
     'terms[]': { required: true },
},
messages:{
    'terms[]': "check the checbox"
}
  • Одиночные кавычки являются обязательными для имени

Ещё вопросы

Сообщество Overcoder
Наверх
Меню