Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13521 -- Corrected javascript comparisons determining when to …

…show and hide the 'add another' inline button. Thanks to darkrho for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13234 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 16c64bc2b723dad2db16db0f75c416ec30f964ad 1 parent 6543539
Russell Keith-Magee authored May 11, 2010
4  django/contrib/admin/media/js/inlines.js
@@ -95,7 +95,7 @@
95 95
 				// Update number of total forms
96 96
 				$(totalForms).val(nextIndex + 1);
97 97
 				// Hide add button in case we've hit the max, except we want to add infinitely
98  
-				if ((maxForms.val() != '') && (maxForms.val() <= totalForms.val())) {
  98
+				if ((maxForms.val() != '') && (maxForms.val()-totalForms.val()) <= 0) {
99 99
 					addButton.parent().hide();
100 100
 				}
101 101
 				// The delete button of each row triggers a bunch of other things
@@ -111,7 +111,7 @@
111 111
 					var forms = $("." + options.formCssClass);
112 112
 					$("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length);
113 113
 					// Show add button again once we drop below max
114  
-					if ((maxForms.val() == '') || (maxForms.val() >= forms.length)) {
  114
+					if ((maxForms.val() == '') || (maxForms.val()-forms.length) > 0) {
115 115
 						addButton.parent().show();
116 116
 					}
117 117
 					// Also, update names and ids for all remaining form controls
2  django/contrib/admin/media/js/inlines.min.js
@@ -2,5 +2,5 @@
2 2
 if(a(this).length&&g){var i;if(a(this).attr("tagName")=="TR"){g=this.eq(0).children().length;a(this).parent().append('<tr class="'+b.addCssClass+'"><td colspan="'+g+'"><a href="javascript:void(0)">'+b.addText+"</a></tr>");i=a(this).parent().find("tr:last a")}else{a(this).filter(":last").after('<div class="'+b.addCssClass+'"><a href="javascript:void(0)">'+b.addText+"</a></div>");i=a(this).filter(":last").next().find("a")}i.click(function(){var e=a("#id_"+b.prefix+"-TOTAL_FORMS"),f=parseInt(e.val()),
3 3
 j=a("#"+b.prefix+"-empty"),d=j.clone(true);d.removeClass(b.emptyCssClass).addClass(b.formCssClass).attr("id",b.prefix+"-"+f).insertBefore(a(j));d.find("*").filter(function(){var c=a(this);return c.attr("id")&&c.attr("id").search(/__prefix__/)>=0}).each(function(){var c=a(this);c.attr("id",c.attr("id").replace(/__prefix__/g,f))}).end().filter(function(){var c=a(this);return c.attr("name")&&c.attr("name").search(/__prefix__/)>=0}).each(function(){var c=a(this);c.attr("name",c.attr("name").replace(/__prefix__/g,
4 4
 f))});if(d.is("tr"))d.children(":last").append('<div><a class="'+b.deleteCssClass+'" href="javascript:void(0)">'+b.deleteText+"</a></div>");else d.is("ul")||d.is("ol")?d.append('<li><a class="'+b.deleteCssClass+'" href="javascript:void(0)">'+b.deleteText+"</a></li>"):d.children(":first").append('<span><a class="'+b.deleteCssClass+'" href="javascript:void(0)">'+b.deleteText+"</a></span>");d.find("input,select,textarea,label,a").each(function(){l(this,b.prefix,e.val())});a(e).val(f+1);h.val()!=""&&
5  
-h.val()<=e.val()&&i.parent().hide();d.find("a."+b.deleteCssClass).click(function(){var c=a(this).parents("."+b.formCssClass);c.remove();b.removed&&b.removed(c);c=a("."+b.formCssClass);a("#id_"+b.prefix+"-TOTAL_FORMS").val(c.length);if(h.val()==""||h.val()>=c.length)i.parent().show();for(var k=0,m=c.length;k<m;k++)a(c.get(k)).find("input,select,textarea,label,a").each(function(){l(this,b.prefix,k)});return false});b.added&&b.added(d);return false})}return this};a.fn.formset.defaults={prefix:"form",
  5
+h.val()-e.val()<=0&&i.parent().hide();d.find("a."+b.deleteCssClass).click(function(){var c=a(this).parents("."+b.formCssClass);c.remove();b.removed&&b.removed(c);c=a("."+b.formCssClass);a("#id_"+b.prefix+"-TOTAL_FORMS").val(c.length);if(h.val()==""||h.val()-c.length>0)i.parent().show();for(var k=0,m=c.length;k<m;k++)a(c.get(k)).find("input,select,textarea,label,a").each(function(){l(this,b.prefix,k)});return false});b.added&&b.added(d);return false})}return this};a.fn.formset.defaults={prefix:"form",
6 6
 addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null}})(django.jQuery);

0 notes on commit 16c64bc

Please sign in to comment.
Something went wrong with that request. Please try again.