--
Ticket URL: <https://code.djangoproject.com/ticket/20929>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I can't reproduce the `DELETE` field rendering with `input type="hidden"`.
For example, modifying
`tests.inline_formsets.tests.DeletionTests.test_deletion`:
{{{
PoemFormSet = inlineformset_factory(Poet, Poem, can_delete=True,
fields="__all__")
for form in formset.forms:
print [str(field) for field in form.visible_fields()]
['<input id="id_poem_set-0-name" maxlength="100"
name="poem_set-0-name" type="text" />',
'<input id="id_poem_set-0-DELETE" name="poem_set-0-DELETE"
type="checkbox" />']
}}}
Am I missing something?
--
Ticket URL: <https://code.djangoproject.com/ticket/20929#comment:1>
Comment (by RLion):
I wonder... It must be me who is missing something...
Here's the template code I use:
{{{
<fieldset class="emails">
<legend class="text-center">{% trans "E-mail" %}</legend>
{{ emails.management_form }}
<div class="inline-form-emails">
{{ emails.empty_form.media }}
{% for hidden in emails.empty_form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% for field in emails.empty_form.visible_fields %}
<div class="form-group">
<label for="{{ field.html_name }}" class="col-xs-12 col-
sm-5 col-md-3 col-lg-3 control-label">
{{ field.label }} {% if field.field.required %}<span
style="color: #a60000;">*</span>{% endif %}
</label>
<div class="col-xs-12 col-sm-7 col-md-9 col-lg-9">
{{ field }}
<span class="help-block">{{ field.help_text }}</span>
</div>
</div>
{% endfor %}
</div>
</fieldset>
}}}
Is something improperly set ? I wonder how my `DELETE field` get that
`type="hidden"`...
Again, here's the view:
{{{#!python
class ContactCreateView(LoginRequiredMixin, CreateView):
template_name = u'frontend/contacts/create.html'
model = Contact
form_class = ContactCreateForm
def get_context_data(self, **kwargs):
context = {
'emails' : inlineformset_factory(parent_model=Contact,
model=ContactEmail, form=ContactEmailCreateForm, extra=0),
}
context.update(kwargs)
return super(ContactCreateView,
self).get_context_data(**context)
}}}
and my `ContactEmailCreateForm`:
{{{#!python
class ContactEmailCreateForm(forms.ModelForm):
# Documentation
__doc__ = _(u'A custom form for ContactEmail model.')
# Methods
def __init__(self, *args, **kwargs):
super(ContactEmailCreateForm, self).__init__(*args, **kwargs)
for name, field in self.fields.items():
if field.widget.attrs.has_key('class'):
field.widget.attrs['class'] += ' form-control'
else:
field.widget.attrs.update({'class':'form-control'})
# Meta-data
class Meta:
model = ContactEmail
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20929#comment:2>
* status: new => closed
* resolution: => worksforme
Comment:
Using these snippets, I can't reproduce the delete field rendering as
hidden. If you could try to reproduce the behavior by writing
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/unit-tests/ a test for Django], that will help us identify the bug (if
one exists). Please reopen this ticket if you can provide that.
--
Ticket URL: <https://code.djangoproject.com/ticket/20929#comment:3>
Comment (by RLion):
I think I might find where the problem came from. It is not a Django bug
nor even an incorrect implementation. As I mentioned it on stack, my
intention was to use django-dynamic-formset. This javascript library was
responsible for the `DELETE` field becoming a `input type="hidden"`
instead of the native checkbox.
Anyway, thank you for your tests.
--
Ticket URL: <https://code.djangoproject.com/ticket/20929#comment:4>