Code

Opened 3 years ago

Closed 3 years ago

#15540 closed (wontfix)

Meta Widgets doesn't work in form.Form

Reported by: silent1mezzo 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:

Description

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.

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.