2014-11-12 3 views

답변

10

직접 작성한 유효성 검사기를 작성해야하지만 매우 간단합니다.

근무 예 : CodePen link

자바 스크립트

$(document).foundation({ 
    abide: { 
     validators: { 
      checkbox_limit: function(el, required, parent) { 
       var group = parent.closest('.checkbox-group'); 
       var min = group.attr('data-abide-validator-min'); 
       var checked = group.find(':checked').length; 
       if (checked >= min) { 
        group.find('small.error').hide(); 
        return true; 
       } else { 
        group.find('small.error').css({ 
         display: 'block' 
        }); 
        return false; 
       } 
      } 
     } 
    } 
}); 

HTML

<form data-abide> 
    <div class="row"> 
     <div class="small-12 column"> 
     <h4>Select your favourite vehicles</h4> 
     </div> 
    </div> 
    <div class="row"> 
     <div class="small-12 columns checkbox-group" data-abide-validator-min="1"> 
     <label> 
      <input type="checkbox" data-abide-validator="checkbox_limit" value="car" /> 
      car 
     </label> 
     <label> 
      <input type="checkbox" data-abide-validator="checkbox_limit" value="train" /> 
      train 
     </label> 
     <label> 
      <input type="checkbox" data-abide-validator="checkbox_limit" value="bicycle" /> 
      bicycle 
     </label> 
     <label> 
      <input type="checkbox" data-abide-validator="checkbox_limit" value="ferry" /> 
      ferry 
     </label> 
     <label> 
      <input type="checkbox" data-abide-validator="checkbox_limit" value="plane" /> 
      plane 
     </label> 
     <small class="error">You have to check at least one vehicle.</small> 
     </div> 
    </div> 
    <div class="row"> 
     <div class="small-12 columns"> 
     <button type="submit">Submit</button> 
     </div> 
    </div> 
</form> 
+0

는 좋은 예를 주셔서 감사합니다. – Elyasin

관련 문제