Opened 9 years ago

Closed 9 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'}),
        }

Change History (1)

comment:1 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed

It doesn't work on 1.7 because UserCreationForm declares the username field so Meta.widgets doesn't have an effect for that field. It does work on 1.8+ because the username field has been removed as of 849538d03df21b69f0754a38ee4ec5f48fa02c52.

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