3

I am trying to validate radio button with parsley.js. Below is the code I am trying to use

  <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>

However, no matter whether I chose yes or no, it still is looking for data required for both. I just want user to be able to chose either yes or no... how Do I do that with parsley.js?

4

3 回答 3

17

要验证 Parsley 中的单选按钮,您只需使用 - data-required="true"。您不需要对单选按钮使用 data-mincheck。由于单选按钮具有相同的名称,因此 parsley 会自动识别它们在同一组中。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">
于 2013-10-23T09:23:31.487 回答
3

我认为无线电输入和复选框是特殊情况,而不是使用 data-required ,您应该使用 data-mincheck 来确保至少选中一个选项。

于 2013-07-13T09:19:35.887 回答
-2

data-mincheck 适用于复选框验证。

data-parsley-required="true" 适用于选项验证

http://parsleyjs.org/doc/examples/simple.html

于 2017-09-18T12:41:31.593 回答