choice.js 1022 B

12345678910111213141516171819202122232425262728
  1. (function($) {
  2. $.fn.bootstrapValidator.validators.choice = {
  3. html5Attributes: ['min', 'max'],
  4. /**
  5. * Check if the number of checked boxes are less or more than a given number
  6. *
  7. * @param {BootstrapValidator} validator The validator plugin instance
  8. * @param {jQuery} $field Field element
  9. * @param {Object} options Consists of following keys:
  10. * - min
  11. * - max
  12. * At least one of two keys is required
  13. * @returns {Boolean}
  14. */
  15. validate: function(validator, $field, options) {
  16. var numChoices = validator
  17. .getFieldElements($field.attr('data-bv-field'))
  18. .filter(':checked')
  19. .length;
  20. if ((options.min && numChoices < options.min) || (options.max && numChoices > options.max)) {
  21. return false;
  22. }
  23. return true;
  24. }
  25. };
  26. }(window.jQuery));