Skip to content

Commit

Permalink
Fixed bug causing generated checkbox elements to always return False …
Browse files Browse the repository at this point in the history
…in Django.Bug report and patch submitted by Wilson.Andrew.J.

git-svn-id: https://django-dynamic-formset.googlecode.com/svn/trunk@5 9f2ace40-7153-11de-83e1-4fc93b4a6815
  • Loading branch information
stan.madueke committed Oct 28, 2009
1 parent 6747931 commit 1f495fc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions demo/example/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ def get_ordereditem_formset(form, formset=models.BaseInlineFormSet, **kwargs):
class ContactInfoForm(forms.Form):
type = fields.ChoiceField(choices=CONTACT_INFO_TYPES)
value = fields.CharField(max_length=200)
preferred = fields.BooleanField(required=False)

ContactFormset = formsets.formset_factory(ContactInfoForm)
5 changes: 3 additions & 2 deletions demo/static/js/jquery.formset.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions demo/templates/example/formset-stacked.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{{ form.type }}
{{ form.value.label_tag }}<br />
{{ form.value }}
{{ form.preferred }} {{ form.preferred.label_tag }}
</div>
{% endfor %}
{{ formset.management_form }}
Expand Down
2 changes: 2 additions & 0 deletions demo/templates/example/formset-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
<table id="id_contact_info_table" border="0" cellpadding="0" cellspacing="5">
<thead>
<tr>
<th scope="col">Preferred</th>
<th scope="col">Type</th>
<th scope="col">Value</th>
</tr>
</thead>
<tbody>
{% for form in formset.forms %}
<tr id="{{ form.prefix }}-row">
<td style="text-align:center;">{{ form.preferred }}</td>
<td>{{ form.type }}</td>
<td>{{ form.value }}</td>
</tr>
Expand Down
3 changes: 2 additions & 1 deletion demo/templates/example/posted-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ <h1 class="title">Posted data</h1>
<strong>Quantity:</strong> {{ form_data.quantity }}
{% else %}
<strong>Type:</strong> {{ form_data.type }}<br />
<strong>Value:</strong> {{ form_data.value }}
<strong>Value:</strong> {{ form_data.value }}<br />
<strong>Preferred:</strong> {{ form_data.preferred }}
{% endif %}
</p>
{% endfor %}
Expand Down
9 changes: 8 additions & 1 deletion src/jquery.formset.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@
$(row).removeAttr('id').insertAfter($('.dynamic-form:last'));
$(row).find('input,select,textarea,label').each(function() {
updateElementIndex(this, options.prefix, nextIndex);
$(this).val('');
// If this is a checkbox or radiobutton, set uncheck it.
// Fix for Issue 1, reported by Wilson.Andrew.J:
var $$ = $(this);
if ($$.is('input:checkbox') || $$.is('input:radio')) {
$$.attr('checked', false);
} else {
$$.val('');
}
});
var formCount = nextIndex + 1;
$('#id_' + options.prefix + '-TOTAL_FORMS').val(formCount);
Expand Down

0 comments on commit 1f495fc

Please sign in to comment.