Opened 15 years ago
Closed 14 years ago
#13633 closed (wontfix)
Add a widget_callback to forms, modelforms, etc
Reported by: | Russell Keith-Magee | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.2 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Modelforms currently support (although undocumented) a formfield_callback method that can be used to control the widgets that are used for a form field. We also support the definition of a 'widgets' attribute in the Meta of a modelform that allows you to override the widget for a particular model field based on the name of the attribute.
We should be able to define a callback to alter the widget programatically, based on the form field that is being rendered.
Attachments (1)
Change History (4)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
Has patch: | set |
---|
I was bitten by the modelformset widget bug (#13095). My patch changes the 5 places where 'formfield_callback' is defaulted from the existing a lambda functions to None. Then right before use, if 'formfield_callback' is still None, set to the proper lambda function. No function signatures change & much DRYer.
Kent
comment:3 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I'd forgotten I'd opened this ticket; it turns out it's not actually possible. The order and expectations with which widgets are instantiated means you need to specify the widget at time of field specification. Pull apart the logic for a ChoiceField if you want to see why.
Thanks @kenth, but the fix you've provided is for the related issue (#13095). I'lll put a reference on that ticket to look here for a patch.
#13095 is related to this.