[Django] #20929: inline_formset - DELETE field is in visible_fields

23 views
Skip to first unread message

Django

unread,
Aug 17, 2013, 9:11:09 AM8/17/13
to django-...@googlegroups.com
#20929: inline_formset - DELETE field is in visible_fields
-------------------------------+--------------------
Reporter: RLion | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
As filled out [http://stackoverflow.com/questions/18281896/django-inline-
formset-delete-fied-in-form-visible-fields here], I wonder why DELETE
field is in visible_fields yet its widget is `input type="hidden"`.
Shouldn't it be in hidden_fields ?

--
Ticket URL: <https://code.djangoproject.com/ticket/20929>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 17, 2013, 7:36:47 PM8/17/13
to django-...@googlegroups.com
#20929: inline_formset - DELETE field is in visible_fields
-------------------------------+--------------------------------------

Reporter: RLion | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timo):

* 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>

Django

unread,
Aug 18, 2013, 9:56:51 AM8/18/13
to django-...@googlegroups.com
#20929: inline_formset - DELETE field is in visible_fields
-------------------------------+--------------------------------------

Reporter: RLion | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

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>

Django

unread,
Aug 18, 2013, 10:45:20 AM8/18/13
to django-...@googlegroups.com
#20929: inline_formset - DELETE field is in visible_fields
-------------------------------+--------------------------------------
Reporter: RLion | Owner: nobody
Type: Uncategorized | Status: closed
Component: Forms | Version: 1.5
Severity: Normal | Resolution: worksforme
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timo):

* 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>

Django

unread,
Aug 18, 2013, 1:03:39 PM8/18/13
to django-...@googlegroups.com
#20929: inline_formset - DELETE field is in visible_fields
-------------------------------+--------------------------------------
Reporter: RLion | Owner: nobody
Type: Uncategorized | Status: closed
Component: Forms | Version: 1.5
Severity: Normal | Resolution: worksforme
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages