#20929 closed Uncategorized (worksforme)
inline_formset - DELETE field is in visible_fields
Reported by: | TonyEight | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.5 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As filled out here, I wonder why DELETE field is in visible_fields yet its widget is input type="hidden"
. Shouldn't it be in hidden_fields ?
Change History (4)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
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:
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
:
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
comment:3 by , 11 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Using these snippets, I can't reproduce the delete field rendering as hidden. If you could try to reproduce the behavior by writing a test for Django, that will help us identify the bug (if one exists). Please reopen this ticket if you can provide that.
comment:4 by , 11 years ago
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.
I can't reproduce the
DELETE
field rendering withinput type="hidden"
. For example, modifyingtests.inline_formsets.tests.DeletionTests.test_deletion
:Am I missing something?