zurb foundation - Display error if no checkbox is checked in checkbox group -


how display error message foundation 5's abide html5 form validation library when no checkboxes checked within same checkbox group?

you have write own abide validator, quite simple.

working example: codepen link

javascript

$(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 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 check @ least 1 vehicle.</small>       </div>    </div>    <div class="row">       <div class="small-12 columns">          <button type="submit">submit</button>       </div>    </div> </form> 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -