admin管理员组

文章数量:1279145

I have a select list on my test form that I am trying to get to work with parsley.js validation.

The parsley validation does work, but only when the default value of the select list is a blank value, except I need to have a value of 0 (zero).

So when the value of zero is selected / displayed in the select list the select list should be red with indicating that there is an error.

How do I get the select list to validate correctly, when I am using a default value of zero?

Here is an example of my select list with the zero value:

<select name="availability_type" id="id_availability_type" data-parsley-id="1601" data-parsley-required="true" data-parsley-required-message="You must enter at least one Detail." class="input-xlarge2 standard_input_style parsley-success">
    <option value="0"> Do not display Availability</option>
    <option value="1">Immediately</option>
    <option value="2">1 week</option>
    <option value="3">2 weeks</option>
    <option value="4">3 weeks</option>
    <option value="5">4 weeks</option>
    <option value="6">&gt; 4 weeks</option>
</select>

Here is the code line that works with a blank space as the value:

<option value=" "> Do not display Availability</option>

I have a select list on my test form that I am trying to get to work with parsley.js validation.

The parsley validation does work, but only when the default value of the select list is a blank value, except I need to have a value of 0 (zero).

So when the value of zero is selected / displayed in the select list the select list should be red with indicating that there is an error.

How do I get the select list to validate correctly, when I am using a default value of zero?

Here is an example of my select list with the zero value:

<select name="availability_type" id="id_availability_type" data-parsley-id="1601" data-parsley-required="true" data-parsley-required-message="You must enter at least one Detail." class="input-xlarge2 standard_input_style parsley-success">
    <option value="0"> Do not display Availability</option>
    <option value="1">Immediately</option>
    <option value="2">1 week</option>
    <option value="3">2 weeks</option>
    <option value="4">3 weeks</option>
    <option value="5">4 weeks</option>
    <option value="6">&gt; 4 weeks</option>
</select>

Here is the code line that works with a blank space as the value:

<option value=" "> Do not display Availability</option>
Share Improve this question edited Sep 19, 2014 at 6:52 user1261774 asked Sep 19, 2014 at 6:33 user1261774user1261774 3,69510 gold badges58 silver badges104 bronze badges 2
  • Is it mandatory to use only the 'numbers' as option value? – kmario23 Commented Sep 19, 2014 at 7:00
  • yes. I have to use a number (0 - 6). – user1261774 Commented Sep 20, 2014 at 19:32
Add a ment  | 

3 Answers 3

Reset to default 8

I finally got this to work using the data-parsley-min="1".

This way the input will not accept the value of zero.

Hope that this helps some one.

To make it work properly you needed to do the following

<!--Do this-->
<select id="select-id" required="" data-parsley-required-message="You must select at least one option.">
  <option value=""> Do not display Availability</option>
  .
  .
</select>

Doing it witht data-parsley-min="1". would make your required message say something stupid like min value has to be at least 1 (even if you override it with the required message attribute)

Hope this helps any other person...

<select class="form-select" id="floatingSelect" aria-label="Floating label select example" data-parsley-required data-parsley-required-message="Please select Country">
<option value="">Choose..</option>
<option value="Ahmedabad">India</option>
<option value="Bombai">UAE</option>
<option value="Delhi">Thailand</option>
<option value="Jammu-Kashmir">Japan</option>
<option value="Jaipur">Irac</option>
<option value="Aagra">Canada</option>
</select>

本文标签: javascriptparsleyjs select list value of zeronot workingStack Overflow