30 lines
1.1 KiB
JavaScript
Executable File
30 lines
1.1 KiB
JavaScript
Executable File
export default function(jQuery) {
|
|
jQuery = jQuery || window.jQuery;
|
|
|
|
jQuery.fn.minmax = function() {
|
|
jQuery(this).each(function() {
|
|
jQuery(this).change(function(e) {
|
|
if (jQuery(this).data('onfix') === true) {
|
|
jQuery(this).data('onfix', false);
|
|
return;
|
|
}
|
|
|
|
var checked = jQuery(this).closest('form').find('[data-minmax]').filter('[name="' + jQuery(this).attr('name') + '"]').filter(':checked').length;
|
|
|
|
var min = parseInt(jQuery(this).attr('min'));
|
|
if (min && checked > min) {
|
|
jQuery(this).data('onfix', true);
|
|
jQuery(this).prop('checked', false).trigger('change');
|
|
return;
|
|
}
|
|
|
|
var max = parseInt(jQuery(this).attr('max'));
|
|
if (max && checked > max) {
|
|
jQuery(this).data('onfix', true);
|
|
jQuery(this).prop('checked', false).trigger('change');
|
|
}
|
|
});
|
|
});
|
|
};
|
|
};
|