Opened 9 years ago

Closed 9 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


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) (2.7 KB) - added by kent@… 9 years ago.
default formfield_callback in a single place

Download all attachments as: .zip

Change History (4)

comment:1 Changed 9 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

#13095 is related to this.

Changed 9 years ago by kent@…

Attachment: added

default formfield_callback in a single place

comment:2 Changed 9 years ago by kenth

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.


comment:3 Changed 9 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

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.

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