Ticket #3515: fields.4.diff

File fields.4.diff, 1.5 KB (added by Simon Litchfield <simon@…>, 18 years ago)

Fixed errors 'sticking'

  • django/newforms/fields.py

     
    3535    # Tracks each time a Field instance is created. Used to retain order.
    3636    creation_counter = 0
    3737
    38     def __init__(self, required=True, widget=None, label=None, initial=None, help_text=None):
     38    def __init__(self, required=True, widget=None, label=None, initial=None, help_text=None, css=None):
    3939        # required -- Boolean that specifies whether the field is required.
    4040        #             True by default.
    4141        # widget -- A Widget class, or instance of a Widget class, that should be
     
    4848        # initial -- A value to use in this Field's initial display. This value is
    4949        #            *not* used as a fallback if data isn't given.
    5050        # help_text -- An optional string to use as "help text" for this Field.
     51        # css -- An optional string to set the CSS class name(s) for this Field.
    5152        if label is not None:
    5253            label = smart_unicode(label)
    5354        self.required, self.label, self.initial = required, label, initial
     
    6061        extra_attrs = self.widget_attrs(widget)
    6162        if extra_attrs:
    6263            widget.attrs.update(extra_attrs)
     64
     65        # Set initial css class name(s)
     66        if css or required:
     67            if required: css = ((css or '') + ' required').lstrip()
     68            widget.attrs.update({'class': css})
     69        self.css = css
    6370
    6471        self.widget = widget
Back to Top