Opened 10 years ago

Closed 10 years ago

#3969 closed (invalid)

Is Not Possible with just a form->template to include both submitted values and errors

Reported by: jon.i.austin@… Owned by: Adrian Holovaty
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


As far as I can tell it isn't possible (using just a form subclass -> template mapping) to return the values submitted as well as any errors -- this means that anytime someone fills out say a very long form and submits it and it comes back with errors they won't get any of their input...
so far as i can tell there's no way to return the submitted values with the errors without specifying the most of the html manually, or just sending back the fields or something funky -- i.e. losing half the point of using a form class.

I tried to do this with multiple forms of the same class using prefix, which prob makes it even stickier.

Am I totally missing something here, is this on the roadmap or a bug?

Change History (5)

comment:1 Changed 10 years ago by anonymous

the problem here appears to be with using prefix -- it seems to work 'magically' if the name of the inputs corresponds one-to-one with the form class

comment:2 Changed 10 years ago by jon.i.austin@…

in fact it completely barfs if bound to a data dict and also given a prefix -- while i see that this is because it loses the mapping from form class var <-> input name -- it makes it worse than useless if attempting to use it in a form that should simply be marked "Updated" and update the current values when there are multiple versions of the same form class instance on the page.

For example I have a preferences page where users can put in sets of search criteria -- each search criteria set is an instance of the same CriteriaForm and so if they add new criteria (via js/dom) or change current criteria and hit submit -- it should just say "Updated" and show the now updated form values -- this is horribly painful with new forms right now.

I'd be more than happy if I'm just missing a technique to make this doable, but I'm wondering whether it is meant to be this way or planning on being changed -- i'm fairly new to django, but i'd definitely be willing to at least look into creating a patch.


comment:3 Changed 10 years ago by anonymous

to fix it I used this in my view code -- basically just created a bound form to find errors then, created a unbound form with the values and transferred the errors over if any:

213             criteria_form_test = CriteriaFormAdv( criteria_dict )
215             # transform things so the errors show up
216             criteria_form = CriteriaFormAdv( initial=criteria_dict, prefix=criteria['prefix'] )
217             for key in criteria_form_test.errors:
218                 criteria_form.errors[key] = criteria_form_test.errors[key]

so not horribly bad, but rather inelegant.

comment:4 Changed 10 years ago by jon.i.austin@…

ah, i see on the newforms-admin branch solves the problem of multiple forms of the same type on the same page (as well as a bounded form with a prefix) -- if this will also solve the problem of the errors and submitted input then feel free to close this bug.

any word on how close this is to inclusion into the trunk?


comment:5 Changed 10 years ago by Simon G. <dev@…>

Resolution: invalid
Status: newclosed

I'm marking this as invalid as it sounds fixed in the newforms-admin. Jon: I'm not sure when this will be merged, but please feel free to drop by Django-developers and help out!

Note: See TracTickets for help on using tickets.
Back to Top