#28531: MultipleChoiceField / CheckboxSelectMultiple values not restored on
bound
forms
--------------------------------------+------------------------
Reporter: Benjamin | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
I'm building the 'edit' page of my form. This page is supposed to show
form with the data that was saved, so the form is pre populated with saved
data. It works fine for most if the fields, but I have a problem with
'MultipleChoiceField' / 'CheckboxSelectMultiple' values that don't get
restored. So instead of having the corresponding checkboxes checked with
data from the saved form, they are all unchecked. This also affects
'SelectMultiple'
Could this be a bug ?
{{{
# forms.py
class MemberForm( forms.ModelForm ):
# ......
MODEL_CATEGORIES = (
('advisor', 'advisor'),
('member', 'member'),
('admin', 'admin'),
)
model_categories = forms.MultipleChoiceField(
widget = forms.CheckboxSelectMultiple,
choices = MODEL_CATEGORIES
)
class Meta:
model = Member
fields = [ 'model_categories' ]
# model
class Member( models.Model ):
model_categories = models.CharField(
max_length = 255,
null = True,
blank = True )
# Controller
def profile_edit_form( request ):
user = request.user or None
# Get user member profile instance
instance = get_object_or_404( Member, author = user )
form = MemberForm( request.POST or None, instance = instance )
context = {
"form" : form,
"instance": instance
}
if form.is_valid():
# ...
return redirect( 'profile_display' )
else:
# Initial form display, and redisplay of invalid form
return render( request, 'profile_edit_form_view.html', context )
# Template
<form action="/accounts/profile-edit-form/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit"/>
</form>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28531>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.e97b99bfff81dead1d7f2af22c675969%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.