Opened 7 years ago

Closed 7 years ago

#15540 closed (wontfix)

Meta Widgets doesn't work in form.Form

Reported by: Adam Mckerlie Owned by: nobody
Component: Forms Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


You can't change the widget in the Meta.widgets for a regular form.

#Doesn't work
class SearchForm(forms.Form):
   search = forms.CharField(max_length=100)

   class Meta:
       widgets = {
           'search': forms.TextInput(attrs={'class': 'class_name'}),

#Works Fine
class SearchForm(forms.Form):
   search = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'class': 'class_name'}))

I feel that this could be extremely confusing for people.

Change History (1)

comment:1 Changed 7 years ago by Karen Tracey

Resolution: wontfix
Status: newclosed

Meta widgets serves a need that only exists for ModelForms: the need to override just the widget used for a field, and not all the other attributes (label, required, etc.) that are auto-generated from the model's field definition. Typically you will specify Meta widgets for fields not explicitly listed in your ModelForm -- if you have explicitly listed a field in your ModelForm I'd consider it better practice to specify the widget on the field definition, rather than off in the Meta widgets dictionary. For a regular form, you need to list all fields anyway, so to me it makes sense that you specify the widgets in the field definition and not elsewhere.

You have not suggested what to do to reduce confusion here. I'd be -1 on adding Meta to regular forms, so I'm closing wontfix on the assumption that that is what you were asking for. If instead there's something specific you think could be added or changed in the docs to help reduce confusion please re-open with details of that.

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