Opened 11 years ago
Closed 11 years ago
#24626 closed Bug (invalid)
widgets property doesn't work in ModelForm
| Reported by: | Felipe de Morais | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | 1.7 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The widgets property of the ModelForm doesn't work as expected adding a class on the input.
from django.forms import DateField, CharField, PasswordInput, TextInput
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from login.models import Fan
class FanForm(UserCreationForm):
birthday = DateField(input_formats=['%d-%m-%Y', '%d/%m/%Y'])
class Meta:
model = Fan
fields = ['username', 'email', 'first_name', 'last_name', 'birthday', 'gender', 'password1', 'password2']
widgets = {
'username': TextInput(attrs={'data': 'meu nome', 'class': 'my-class'}),
}
Note:
See TracTickets
for help on using tickets.
It doesn't work on 1.7 because
UserCreationFormdeclares theusernamefield soMeta.widgetsdoesn't have an effect for that field. It does work on 1.8+ because theusernamefield has been removed as of 849538d03df21b69f0754a38ee4ec5f48fa02c52.