#27220: MultiWidget not considered in form submit
--------------------------+--------------------------------------
     Reporter:  andreage  |                    Owner:  nobody
         Type:  Bug       |                   Status:  new
    Component:  Forms     |                  Version:  1.10
     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 andreage):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> I have a custom widget for a field, for example:
>
> {{{
> class TestWidget(MultiWidget):
>     def __init__(self, attrs=None):
>         widgets = (
>             Select(choices=func_start()),
>             Select(choices=func_end())
>         )
>         super(TestWidget, self).__init__(widgets, attrs)
>
>     ...
>

> class TestModel(models.Model)
>   test = ArrayField(models.PositiveSmallIntegerField(), default=list,
> blank=True)
>

> class TestForm(forms.ModelForm):
>     def __init__(self, *args, **kwargs):
>         super(TestForm, self).__init__(*args, **kwargs)
>         self.fields['test'].widget = SlotsWidget(self.facility)
> }}}
>
> It's been working fine until Django 10.0. With Django 10.1 and
> specifically due to this commit it breaks.
>
> https://github.com/django/django/commit/4bc6b939944183533ae74791d21282e613f63a96
> #diff-70af885c2725fe87eb3b99a393268d10
>
> `f.name` in this commit would be "test", but `form.data` would contain
> "test_0" and "test_1". For this reason form content is skipped and not
> saved to the form instance.

New description:

 I have a custom widget for a field, for example:

 {{{
 class TestWidget(MultiWidget):
     def __init__(self, attrs=None):
         widgets = (
             Select(choices=func_start()),
             Select(choices=func_end())
         )
         super(TestWidget, self).__init__(widgets, attrs)

     ...


 class TestModel(models.Model)
   test = ArrayField(models.PositiveSmallIntegerField(), default=list,
 blank=True)


 class TestForm(forms.ModelForm):
     def __init__(self, *args, **kwargs):
         super(TestForm, self).__init__(*args, **kwargs)
         self.fields['test'].widget = SlotsWidget(self.facility)
 }}}

 It's been working fine until Django 10.0. With Django 10.1 and
 specifically due to this commit it breaks.

 
https://github.com/django/django/commit/4bc6b939944183533ae74791d21282e613f63a96
 #diff-70af885c2725fe87eb3b99a393268d10

 `f.name` in this commit would be "test", but `form.data` would contain
 "test_0" and "test_1". For this reason form field content is skipped and
 not saved to the form instance.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/27220#comment:1>
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/066.d8295b36c3f8fe0dc87c3ab70c726351%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to