1

I am trying to create custom validation for my form but it doesnt seem to work when bootstrap modal is not opened

here is my form

 <form action="{% url 'seller_details' %}" method="post" id="seller_details">
      {% csrf_token %}
<input type="button" value="SELECT" data-toggle="modal" data-target="#catmodal" name="select_brand"></td></tr>
              <!-- Modal -->
              <div id="catmodal" class="modal fade" role="dialog">
                <div class="modal-dialog" style="width:1000px">
                  <!-- Modal content-->
                  <div class="modal-content"style="height: 600px">
                    <div class="modal-header text-center">
                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                      <h4 class="modal-title">Select Brand & Category</h4>
                    </div>
                    <div class="modal-body">

                      <div class="modal-left">
                        <ul>
                          <div class="heading">Brands</div>
                            <li><input type="radio" value="spykar" name="brand" onclick="getCategories(event)">spykar</li>

                            <li><input type="radio" value="Madame" name="brand" onclick="getCategories(event)">Madame</li>

                            <li><input type="radio" value="KidsBerry" name="brand" onclick="getCategories(event)">KidsBerry</li>


                            <li><input type="radio" value="Park Avenue" name="brand" onclick="getCategories(event)">Park Avenue</li>

                            <li><input type="radio" value="Numero Uno" name="brand" onclick="getCategories(event)">Numero Uno</li>


                          </ul>
                        </div>

                       <div class="modal-right">
                         <ul>
                           <div class="heading">Categories</div>
                           <div id="categories">
                           </div>
                         </ul>
                       </div>
                     </div>
                     <input type="submit" value="submit" id="brand_category">
                   </div>
                 </div>
               </div>
             </div>
             <tr><td></td><td><input type="submit" value="submit" style="width:28%; margin-left:5px;"></td></tr>
           </table>
        </div>
      </form>

here is my custom validation method

$.validator.addMethod("select_brand", function(value, element) {
     var brand = $('input[name="' + element.name + '"]:checked').length > 0;
     console.log(brand)
     return brand
}, "Must Select Brand");

here is the validate function

 $("#seller_details").validate({

        rules: {
            brand :  { select_brand : true },

        },

        messages: {
            select_brand:"Please Select Brand and Category",

        },

   submitHandler: function(form) {
            form.submit();
        }

Problem Here is that the custom validation method works only when the bootstrap modal is opened How can i make the custom validate to work.Thank you

asing177
  • 934
  • 2
  • 13
  • 34
  • Kindly provide your generated HTML, rather than providing the server-side code – AsgarAli Feb 29 '16 at 14:46
  • included the generated html – asing177 Feb 29 '16 at 14:56
  • You want that any one option of radio button must be selected. Is it OK if you get the solution without custom rule ? – AsgarAli Feb 29 '16 at 15:01
  • i know how to get that without the custom rule....but on submit of form all the custom rules are displayed without the radio one...I am more curious to know why its not working – asing177 Feb 29 '16 at 15:18
  • But still u can give your solution – asing177 Feb 29 '16 at 15:24
  • On a side note, your html is not valid. For example, DIV elements are not allowed inside a UL tag. http://stackoverflow.com/questions/8557869/is-this-html-structure-valid-ul-div-li-li-div-li-li-div – phenxd Feb 29 '16 at 15:34
  • Thanks @phenxd for ur notifi – asing177 Feb 29 '16 at 15:41
  • Also, in the beginning, you have an opening FORM tag, and 3 lines under a closing TABLE tag. I think it should be an opening TABLE tag. Stuff like that could possibly (not sure) interfere with your javascript – phenxd Feb 29 '16 at 15:48
  • Actually i edited the html to include in the question..thats why ...removed the table tag now – asing177 Feb 29 '16 at 16:32

0 Answers0