Code

Opened 3 years ago

Closed 3 years ago

#15256 closed (invalid)

FormSet does not respect initial values after binding

Reported by: mnbayazit Owned by: nobody
Component: Forms Version: master
Severity: Keywords: formset
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by russellm)

After the form is posted, if an empty form is generated, it will be completely empty rather than having the initial values specified on the form. I believe we can fix this by modifying _construct_form like so:

        if self.is_bound and i < self.initial_form_count():
            defaults['data'] = self.data
            defaults['files'] = self.files

And completely remove this chunk from _get_empty_form

        if self.is_bound:
            defaults['data'] = self.data
            defaults['files'] = self.files

I don't know why an empty form should behave any differently after the formset has been bound... it only seems to be causing problems.

Attachments (0)

Change History (2)

comment:1 in reply to: ↑ description Changed 3 years ago by mnbayazit

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Nevermind... I don't my proposed fix works that well. But this is still a bug and I don't know how to get around it :\

comment:2 Changed 3 years ago by russellm

  • Description modified (diff)
  • Resolution set to invalid
  • Status changed from new to closed

When providing a bug report, you should spend less time tell us how to fix the problem, and more time explaining the problem itself. If you're going to provide a code sample, make it a code sample that demonstrates the problem.

I can't work out how to reproduce the problem from the instructions provided; closing invalid. Feel free to reopen if you want to provide a reproducible test case.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.