用parsley.js验证单选按钮

Hel*_*rse 3 html validation jquery parsley.js

我正在尝试使用parsley.js验证单选按钮.以下是我尝试使用的代码

  <p id="registration_field_custom2" class="onefield registration_field_custom2">
  <span class="doyou">
  <span class="text">etc etc etc etc ?</span>
    <input type="radio" name="custom2" value="Yes" id="custom2_yes" 
        data-required="true" 
        data-error-container="#submitDetails .error6" 
        data-error-message ="Please chose either yes or no"
    />
    <label for="custom2_yes">Yes</label>
    <input type="radio" name="custom2" value="No" id="custom2_no"  
    />
    <label for="custom2_no">No</label>     
  </span>
  </p>
Run Code Online (Sandbox Code Playgroud)

但是,无论我选择是或否,它仍然在寻找两者所需的数据.我只是希望用户能够选择是或否......我如何使用parsley.js做到这一点?

Rom*_*man 15

要验证Parsley中的单选按钮,您只需要使用 - data-required ="true".您不需要使用data-mincheck作为单选按钮.由于单选按钮具有相同的名称,因此欧芹自动识别出它们位于同一组中.Parsley文档中有很好的例子:http://parsleyjs.org/doc/index.html

例:

<input id="radio-required" class="parsley-validated" type="radio" data-required="true" value="foo" name="radiorequired">
<input id="radio-required2" type="radio" value="bar" name="radiorequired">
Run Code Online (Sandbox Code Playgroud)