-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.easy-checkbox-required.js
1 lines (1 loc) · 1.52 KB
/
jquery.easy-checkbox-required.js
1
!function(t,e){function a(a){var o=t(this).closest("form"),s=o.data(n+"-message-template-single")||"Please choose an option",r=o.data(n+"-message-template-min")||"Please choose at least {min} options",c=o.data(n+"-message-template-range")||"Please choose {min}-{max} options",l=o.data(n+"-message-template-max")||"Please choose at most {max} options",u=[],f=!1;o.find(i).each(function(){var a,o,i,h=t(this),p=h.attr("name");return d(this),-1==t.inArray(p,u)?(u.push(p),a=h.data(n).toString().split("-"),o=h.closest("form").find('[type=checkbox][name="'+p+'"]:checked').length,""==a&&(a=[1]),o<a[0]&&(f=!0),f===!1&&a[1]!=e&&o>a[1]&&(f=!0),f?(i=a[1]==e?1==a[0]?s:r:0==a[0]?l:c,i=i.replace("{min}",a[0]).replace("{max}",a[1]),m(this,i),!1):void 0):void 0})}function o(a){var o=t(this),n=!1,l=[];return o.find(i).each(function(){var a=this,o=t(a),i=o.attr("name");-1==t.inArray(i,l)&&(l.push(i),o.data(s)!=e?(n=!0,o.closest(r).addClass(c)):o.closest(r).removeClass(c))}),!n}if(t!=e){var n="checkbox-required",i="[data-"+n+"]",s=n+"-error",r="form > ol > li, fieldset > ol > li",c="validation-error",l=function(t){var e=document.createElement("input");return"function"!=typeof e.setCustomValidity?!1:!0}(),m=function(){},d=function(){};l?(m=function(t,e){t.setCustomValidity(e)},d=function(t){t.setCustomValidity("")}):(m=function(e,a){t(e).data(s,a)},d=function(e){t(e).removeData(s)}),t(i).each(function(){var e=t(this).closest("form");e.data(n)||(e.on("script::load",a).on("change",i,a).data(n,!0).triggerHandler("script::load"),l||e.on("submit",o))})}}(jQuery);