diff --git a/django/contrib/admin/media/js/inlines.js b/django/contrib/admin/media/js/inlines.js
index 4e397b6..1f5933f 100644
a
|
b
|
|
56 | 56 | var template = $("#" + options.prefix + "-empty"); |
57 | 57 | var row = template.clone(true).get(0); |
58 | 58 | $(row).removeClass(options.emptyCssClass).removeAttr("id").insertBefore($(template)); |
59 | | $(row).html($(row).html().replace(/__prefix__/g, nextIndex)); |
| 59 | $(row).html($(row).html().replace(new RegExp(options.empty_form_prefix, "g"), nextIndex)); |
60 | 60 | $(row).addClass(options.formCssClass).attr("id", options.prefix + nextIndex); |
61 | 61 | if ($(row).is("TR")) { |
62 | 62 | // If the forms are laid out in table rows, insert |
… |
… |
|
118 | 118 | /* Setup plugin defaults */ |
119 | 119 | $.fn.formset.defaults = { |
120 | 120 | prefix: "form", // The form prefix for your django formset |
| 121 | empty_form_prefix: "__prefix__",// The magic prefix bit on the empty form. |
121 | 122 | addText: "add another", // Text for the add link |
122 | 123 | deleteText: "remove", // Text for the delete link |
123 | 124 | addCssClass: "add-row", // CSS class applied to the add link |
diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html
index fb112a0..81879d0 100644
a
|
b
|
|
50 | 50 | } |
51 | 51 | $(rows).formset({ |
52 | 52 | prefix: "{{ inline_admin_formset.formset.prefix }}", |
| 53 | empty_form_prefix: "{{ inline_admin_formset.formset.empty_form_prefix }}", |
53 | 54 | addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}", |
54 | 55 | formCssClass: "dynamic-{{ inline_admin_formset.formset.prefix }}", |
55 | 56 | deleteCssClass: "inline-deletelink", |
diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
index dc9552f..d56944a 100644
a
|
b
|
|
96 | 96 | } |
97 | 97 | $(rows).formset({ |
98 | 98 | prefix: "{{ inline_admin_formset.formset.prefix }}", |
| 99 | empty_form_prefix: "{{ inline_admin_formset.formset.empty_form_prefix }}", |
99 | 100 | addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}", |
100 | 101 | formCssClass: "dynamic-{{ inline_admin_formset.formset.prefix }}", |
101 | 102 | deleteCssClass: "inline-deletelink", |
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index ec14f81..03aa7ba 100644
a
|
b
|
class BaseFormSet(StrAndUnicode):
|
32 | 32 | """ |
33 | 33 | A collection of instances of the same Form class. |
34 | 34 | """ |
| 35 | empty_form_prefix = '__prefix__' |
| 36 | |
35 | 37 | def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, |
36 | 38 | initial=None, error_class=ErrorList): |
37 | 39 | self.is_bound = data is not None or files is not None |
… |
… |
class BaseFormSet(StrAndUnicode):
|
125 | 127 | def _get_empty_form(self, **kwargs): |
126 | 128 | defaults = { |
127 | 129 | 'auto_id': self.auto_id, |
128 | | 'prefix': self.add_prefix('__prefix__'), |
| 130 | 'prefix': self.add_prefix(self.empty_form_prefix), |
129 | 131 | 'empty_permitted': True, |
130 | 132 | } |
131 | 133 | if self.data or self.files: |
diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py
index 3eecb7f..6c9bf01 100644
a
|
b
|
|
1 | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | from django import forms |
| 4 | from django.forms.formsets import formset_factory |
| 5 | from django.test import TestCase |
| 6 | |
| 7 | class EmptyFormTestCase(TestCase): |
| 8 | def test_custom_empty_form_prefix(self): |
| 9 | class BasicForm(forms.Form): |
| 10 | value = forms.CharField() |
| 11 | |
| 12 | FormSet = formset_factory(BasicForm) |
| 13 | FormSet.empty_form_prefix = "__pony__" |
| 14 | self.assertEqual(str(FormSet().empty_form), """<tr><th><label for="id_form-__pony__-value">Value:</label></th><td><input type="text" name="form-__pony__-value" id="id_form-__pony__-value" /></td></tr>""") |
| 15 | |
| 16 | |
2 | 17 | tests = """ |
3 | 18 | # Basic FormSet creation and usage ############################################ |
4 | 19 | |
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py
index 8757e79..e50a10f 100644
a
|
b
|
from localflavor.za import tests as localflavor_za_tests
|
34 | 34 | from regressions import tests as regression_tests |
35 | 35 | from util import tests as util_tests |
36 | 36 | from widgets import tests as widgets_tests |
37 | | from formsets import tests as formset_tests |
| 37 | from formsets import tests as formset_tests, EmptyFormTestCase |
38 | 38 | from media import media_tests |
39 | 39 | |
40 | 40 | from fields import FieldsTests |