Opened 13 years ago

Closed 13 years ago

#17170 closed Bug (duplicate)

django.forms.fields.CharField.widget_attrs wrong return

Reported by: Csaba Tóth Owned by: nobody
Component: Forms Version: 1.3
Severity: Normal 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

The "django.forms.fields.CharField" objects method widget_attrs haven't got enough return, it should return with empty dict if the if runs to false. But i think the best if it calls the super class' method, which is yet returns an empty dict (django.forms.fields.Field)

    def widget_attrs(self, widget):
        if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)):
            # The HTML attribute is maxlength, not max_length.
            return {'maxlength': str(self.max_length)}
+       else:
+           return Field.widget_attrs(self, widget)

Change History (3)

comment:1 by Csaba Tóth, 13 years ago

Because it returns None, this code didn't work for me:

from django import forms

class DomainRecForm(forms.Form):
    host = forms.CharField(max_length=50, label='Host Name', required=False)
    value_name = forms.CharField(max_length=500, label='Host Address (by name)', required=False, widget=forms.Textarea)

drc = DomainRecForm(data=request.POST)
h = forms.HiddenInput()
h.attrs.update(drc.fields['value_ip'].widget_attrs(h))
drc.fields['value_name'].widget = h

Because widget_attr(forms.HiddenInput()) returns a None object, and {}.update(None) throws an exception

comment:2 by Julien Phalip, 13 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Preston Timmons, 13 years ago

Resolution: duplicate
Status: newclosed

Thanks for the report. Closing this ticket as a duplicate of #15912.

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