jquery doğrulama eklentisi: Bazı koşulu ile onaylayın

0 Cevap php

Ben jquery validator eklentisi kullanıyorum. ben bazı koşulu ile bazı alan doğrulamak gerekir. Bunu nasıl uygularım?

i have a form where user select a country..then user creates branch on the fly, now i want to validate that if user do not select a county then prompt to select country and if user select a country then prompt to create atleast one branch.

i kadar ne

Kullanıcı herhangi bir şube oluşturmak eğer şube sayma gizli bir alan vardır. ben bu gizli alan için doğrulamak eğer o her zaman doğru dönün böylece ama bu alan (sayfa yük) daha önce, şube oluşturduktan sonra hiçbir değeri gelmiştir doldurulur. ben ne yapmalıyım

burada ben kullandım kod parçacığını ama ben yukarıdaki tüm işlemek için daha iyi bir yolu olmalı biliyorum .. bana bunu yolunu optimize önermek için lütfen

<script type="text/javascript">
jQuery.metadata.setType("attr", "validate");

jQuery('#createForm').submit(function(){
        if(jQuery("#hasbranch").val()== 0 ){
            jQuery(".brancherror").html('Atleast one branch is necessary');
            return false;
        }
    });

var validator=jQuery("#createForm").validate({
               rules: { list of rules},
               messgae : { list of messages },                                
});
</script>

<form name="createForm" id="createForm">
<table>
<tr>
      <td>Select Country :</td>
      <td >
      <select name="country_id" id="country"  class="selectbox" onchange="return showBranch();"     title="Please select country" validate="required:true"  >
    <option value="" >Select Country </option>
    <?php foreach($this->country as $key => $country) { ?>
    <option value="<?php echo $country->id; ?>"<?php if ($country->id == $this->ad_data['country_id']) {?> selected="selected" <?php } ?> > <?php echo $country->name; ?></option> 
    <?php } // end of foreach ?>
      </select>
      </td>
  </tr>
  <tr>
      <td> //Here is link to add branch (via iframe) </td>
  </tr>    
  </table>
   <input type="hidden" value="<?php echo count($_SESSION['branches'])? 1: 0 ;?> name="hasbranch" id="hasbranch" />
   </form>  

0 Cevap