Opened 14 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)

models.py-diffs (2.7 KB ) - added by kent@… 14 years ago.
default formfield_callback in a single place

Download all attachments as: .zip

Change History (4)

comment:1 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

#13095 is related to this.

by kent@…, 14 years ago

Attachment: models.py-diffs added

default formfield_callback in a single place

comment:2 by kenth, 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 Russell Keith-Magee, 14 years ago

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