Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #24 from marcneuwirth/master

Removed 'return false' in favor of preventDefault in admin JS.
  • Loading branch information...
commit 04785d2697b05186362b8d430c06109cdb91c069 2 parents 243b99c + b719cbb
Adrian Holovaty authored May 18, 2012
26  django/contrib/admin/static/admin/js/inlines.js
@@ -31,11 +31,11 @@
31 31
 			}
32 32
 		};
33 33
 		var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS").attr("autocomplete", "off");
34  
-		var nextIndex = parseInt(totalForms.val());
  34
+		var nextIndex = parseInt(totalForms.val(), 10);
35 35
 		var maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").attr("autocomplete", "off");
36 36
 		// only show the add button if we are allowed to add more items,
37 37
         // note that max_num = None translates to a blank string.
38  
-		var showAddButton = maxForms.val() == '' || (maxForms.val()-totalForms.val()) > 0;
  38
+		var showAddButton = maxForms.val() === '' || (maxForms.val()-totalForms.val()) > 0;
39 39
 		$(this).each(function(i) {
40 40
 			$(this).not("." + options.emptyCssClass).addClass(options.formCssClass);
41 41
 		});
@@ -52,13 +52,14 @@
52 52
 				$(this).filter(":last").after('<div class="' + options.addCssClass + '"><a href="javascript:void(0)">' + options.addText + "</a></div>");
53 53
 				addButton = $(this).filter(":last").next().find("a");
54 54
 			}
55  
-			addButton.click(function() {
  55
+			addButton.click(function(e) {
  56
+				e.preventDefault();
56 57
 				var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS");
57 58
 				var template = $("#" + options.prefix + "-empty");
58 59
 				var row = template.clone(true);
59 60
 				row.removeClass(options.emptyCssClass)
60  
-				    .addClass(options.formCssClass)
61  
-				    .attr("id", options.prefix + "-" + nextIndex);
  61
+					.addClass(options.formCssClass)
  62
+					.attr("id", options.prefix + "-" + nextIndex);
62 63
 				if (row.is("tr")) {
63 64
 					// If the forms are laid out in table rows, insert
64 65
 					// the remove button into the last table cell:
@@ -78,14 +79,15 @@
78 79
 				// Insert the new form when it has been fully edited
79 80
 				row.insertBefore($(template));
80 81
 				// Update number of total forms
81  
-				$(totalForms).val(parseInt(totalForms.val()) + 1);
  82
+				$(totalForms).val(parseInt(totalForms.val(), 10) + 1);
82 83
 				nextIndex += 1;
83 84
 				// Hide add button in case we've hit the max, except we want to add infinitely
84  
-				if ((maxForms.val() != '') && (maxForms.val()-totalForms.val()) <= 0) {
  85
+				if ((maxForms.val() !== '') && (maxForms.val()-totalForms.val()) <= 0) {
85 86
 					addButton.parent().hide();
86 87
 				}
87 88
 				// The delete button of each row triggers a bunch of other things
88  
-				row.find("a." + options.deleteCssClass).click(function() {
  89
+				row.find("a." + options.deleteCssClass).click(function(e) {
  90
+					e.preventDefault();
89 91
 					// Remove the parent form containing this button:
90 92
 					var row = $(this).parents("." + options.formCssClass);
91 93
 					row.remove();
@@ -98,7 +100,7 @@
98 100
 					var forms = $("." + options.formCssClass);
99 101
 					$("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length);
100 102
 					// Show add button again once we drop below max
101  
-					if ((maxForms.val() == '') || (maxForms.val()-forms.length) > 0) {
  103
+					if ((maxForms.val() === '') || (maxForms.val()-forms.length) > 0) {
102 104
 						addButton.parent().show();
103 105
 					}
104 106
 					// Also, update names and ids for all remaining form controls
@@ -110,17 +112,15 @@
110 112
 							updateElementIndex(this, options.prefix, i);
111 113
 						});
112 114
 					}
113  
-					return false;
114 115
 				});
115 116
 				// If a post-add callback was supplied, call it with the added form:
116 117
 				if (options.added) {
117 118
 					options.added(row);
118 119
 				}
119  
-				return false;
120 120
 			});
121 121
 		}
122 122
 		return this;
123  
-	}
  123
+	};
124 124
 	/* Setup plugin defaults */
125 125
 	$.fn.formset.defaults = {
126 126
 		prefix: "form",					// The form prefix for your django formset
@@ -132,5 +132,5 @@
132 132
 		formCssClass: "dynamic-form",	// CSS class applied to each form in a formset
133 133
 		added: null,					// Function called each time a new form is added
134 134
 		removed: null					// Function called each time a form is deleted
135  
-	}
  135
+	};
136 136
 })(django.jQuery);

0 notes on commit 04785d2

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