diff --git a/src/jquery.formset.min.js b/src/jquery.formset.min.js new file mode 100644 index 0000000..f2985b8 --- /dev/null +++ b/src/jquery.formset.min.js @@ -0,0 +1 @@ +(function(e){e.fn.formset=function(t){t.prefix=t.prefix||e(this).data("prefix");var n=e.extend({},e.fn.formset.defaults,t),r=n.extraClasses.join(" "),i=e("#id_"+n.prefix+"-TOTAL_FORMS"),s=e("#id_"+n.prefix+"-MAX_NUM_FORMS"),o=Math.max(1,n.minNum||parseInt(e("#id_"+n.prefix+"-INITIAL_FORMS").val())),u="input,select,textarea,label,div",a=e(this),f=function(e,t){if(n.extraClasses){e.removeClass(r);e.addClass(n.extraClasses[t%n.extraClasses.length])}},l=function(e,t,n){var r=new RegExp(t+"-(\\d+|__prefix__)-"),i=t+"-"+n+"-";if(e.attr("for"))e.attr("for",e.attr("for").replace(r,i));if(e.attr("id"))e.attr("id",e.attr("id").replace(r,i));if(e.attr("name"))e.attr("name",e.attr("name").replace(r,i))},c=function(e){return e.find(u).length>0},h=function(){return s.length==0||s.val()==""||s.val()-i.val()>0},p=function(t,r){if(r'+n.deleteText+"")}else if(t.is("UL")||t.is("OL")){t.append('
  • '+n.deleteText+"
  • ")}else if(t.find("a."+n.deleteCssClass).length==0){t.append(''+n.deleteText+"")}t.find("a."+n.deleteCssClass).click(function(){var t=e(this).parents("."+n.formCssClass),r=t.find('input:hidden[id $= "-DELETE"]'),s=t.siblings("a."+n.addCssClass+", ."+n.formCssClass+"-add"),o;if(r.length){r.val("on");t.hide();o=e("."+n.formCssClass).not(":hidden")}else{t.remove();o=e("."+n.formCssClass).not(".formset-custom-template");i.val(o.length)}for(var a=0,c=o.length;a');r.hide()}else{i.before('')}e('label[for="'+i.attr("id")+'"]').hide();i.remove()}if(c(r)){r.addClass(n.formCssClass);if(r.is(":visible")){p(r,t);f(r,t)}}});if(a.length){var d=!h(),v,m;if(n.formTemplate){m=n.formTemplate instanceof e?n.formTemplate:e(n.formTemplate);m.removeAttr("id").addClass(n.formCssClass+" formset-custom-template");m.find(u).each(function(){l(e(this),n.prefix,"__prefix__")})}else{m=e("."+n.formCssClass+":last").clone(true).removeAttr("id");m.find('input:hidden[id $= "-DELETE"]').remove();m.find(u).not(n.keepFieldValues).each(function(){var t=e(this);if(t.is("input:checkbox")||t.is("input:radio")){t.attr("checked",false)}else{t.val("")}})}n.formTemplate=m;if(a.attr("tagName")=="TR"){var g=a.eq(0).children().length,y=e(''+n.addText+"").addClass(n.formCssClass+"-add");a.parent().append(y);if(d)y.hide();v=y.find("a")}else{e("a."+n.addCssClass).remove();a.filter(":last").after(''+n.addText+"");v=a.filter(":last").next();if(d)v.hide()}v.click(function(){var t=parseInt(i.val()),r=n.formTemplate.clone(true).removeClass("formset-custom-template"),s=e(e(this).parents("tr."+n.formCssClass+"-add").get(0)||this);f(r,t);r.insertBefore(s).show();r.find(u).each(function(){l(e(this),n.prefix,t)});i.val(t+1);p(r,t+1);if(!h())s.hide();if(n.added)n.added(r);return false})}return a};e.fn.formset.defaults={prefix:null,minNum:null,formTemplate:null,addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",formCssClass:"dynamic-form",extraClasses:[],keepFieldValues:"",added:null,removed:null}})(jQuery) \ No newline at end of file