#24453: Initial values for ManyToMany form fields can't be hidden
----------------------------+--------------------
     Reporter:  girzel      |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Forms       |    Version:  1.7
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 Initial values can be provided for the ManyToMany field of a ModelForm, to
 be used in a ModelFormSet, but if the widget is switched to the
 HiddenInput class, the (as far as I can tell correct) initial value
 creates a validation error:

 (Hidden field <field_name>) Enter a list of values.

 Take this model:

 {{{
 class Work(models.Model):
   authors = models.ManyToManyField(Author)

 initial = dict(authors=[some_author_instance])

 formset = WorkFormSet(queryset=Work.objects.none(), initial=[initial])
 }}}

 This is supposing one extra form in the formset. If the "authors" field
 remains unhidden, the initial value works as expected. If we switch the
 "authors" widget to a forms.HiddenInput, however, I get the above
 validation error.

 I don't think simply hiding the input should affect how the initial values
 are treated. FWIW, here's an example what the hidden input looks like in
 the HTML:

 `<input id="id_form-1-authors" name="form-1-authors" type="hidden"
 value="[37L]" />`

 So presumably "[37L]" isn't getting read as a list, somewhere...

--
Ticket URL: <https://code.djangoproject.com/ticket/24453>
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/049.b2da3a7b31d75e16fce91ed40909cf2b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to