vendredi 17 avril 2015

Atleast one drop down value is more than 0 from multiple drop downs - jQuery Validator

Two different drop down selection with jQuery validate validation


Let's use below HTML





// Validate Add Post page At front-end Full Access form
jQuery("#add_post").validate({
rules:{
post_title: {
required: true
},
category: {
require_from_group: [1, ".postselection"]
},
group_category: {
require_from_group: [1, ".postselection"]
}
},
messages:{
post_title: {
required: "Please Enter Your Post Title"
},
category: {
require_from_group : "Please select either category or group"
},
group_category: {
require_from_group : "Please select either category or group"
}
}
});



<script src="http://ift.tt/1rKdStd"></script>
<script src="http://ift.tt/Y44mcc"></script>
<script src="http://ift.tt/1xh5DvV"></script>
<form action="" method="post" accept-charset="utf-8" id="add_post" name="myform" enctype="multipart/form-data" novalidate="novalidate">

<input type="text" name="post_title" value="" id="post_title" placeholder="Enter Title Here" class="inputtxt">

<select name="category" id="category" class="postselection valid" aria-invalid="false">
<option value="0">Please Select Your Category</option>
<option value="101">Sports</option>
<option value="102">Startups</option>
<option value="103">Travel</option>
<option value="106">Weather</option>
<option value="107">Wisdom</option>
<option value="108">Writing</option>
</select>

OR

<select name="group_category" id="group_category" aria-invalid="false" class="mygroup postselection valid">
<option value="0">Select one of your groups</option>
<option value="11">New Launch Updates</option>
<option value="12">Smile Groups</option>
<option value="13">Social Enterprise</option>
<option value="14">Developers Corner</option>
<option value="15">WordPress</option>
</select>

<input type="submit" name="submit" value="Submit Post" id="add-new-post">

</form>



======================================================================


We have 2 multiple drop down here and I want either one selected both of one and that value must be greater than zero.


By default all drop down selected with first option. So, require_from_group not throwing validation error any time and I must want selection which are not selected by default.


In short,




  • Either one option selected from numbers of drop downs




  • And that value must to zero (default selection)




(Note: Use JQuery validator for validation is compulsory)


Let me know if you want further explanation with code snippet.


Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire