Opened 13 years ago

Last modified 9 years ago

#17533 closed New feature

When attempting to build more complex widgets/fields, access to form data would be helpful — at Initial Version

Reported by: freyley Owned by: nobody
Component: Forms Version:
Severity: Normal Keywords:
Cc: kmike84@…, andrebrantom Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I'm currently working on building more complex fields with multi-html-element widgets, and connecting them to incoming data models in a way that I think isn't doable in the current design of forms. However, there is a place where fields have access to form data, and that's in the BoundField class in forms.py. If I build my own BoundField class, I can easily give my fields access to the data they need when rendering the widget, as the value() method has access to self.form and self.field. Unfortunately, to build my own BoundField class I have to implement a number of functions in the BaseForm class, one of which, _html_output, is long and not something I actually want to maintain a different version of.

So I propose a minor modification: have BaseForm.init set a self._bound_field_class and then use that everywhere, which allows Form class derivatives to set a different BoundField class.

I am attaching a patch which does just that. It is against 1.3.1

Change History (1)

by freyley, 13 years ago

Attachment: boundfield.patch added

Or better, set it as a class variable

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