Changeset 2054

Show
Ignore:
Timestamp:
06/19/09 20:28:21 (9 months ago)
Author:
JensDiemer
Message:

Add background-color into input tag
TODO: Change text color, if background is to dark ;)
TODO2: Use jQuery to change the <td> background color ;)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/pylucid_project/apps/pylucid/fields.py

    r2052 r2054  
    4646        raise exceptions.ValidationError(_("Error: %r is not a CSS hex color value") % value) 
    4747 
     48class ColorInputWidget(forms.TextInput): 
     49    """ 
     50    Add background-color into input tag 
     51    TODO: Change text color, if background is to dark ;) 
     52    TODO2: Use jQuery to change the <td> background color ;) 
     53    """ 
     54    def render(self, name, value, attrs=None): 
     55        if not attrs: 
     56            attrs = {} 
     57        attrs["style"] = "background-color:#%s;" % value 
     58        return super(ColorInputWidget, self).render(name, value, attrs) 
     59 
    4860 
    4961class ColorFormField(forms.CharField): 
    5062    """ form field for a CSS color value """ 
    51 #    widget = DictFormWidget 
     63    widget = ColorInputWidget 
    5264    def clean(self, value): 
    5365        """ validate the form data """ 
    5466        value = super(ColorFormField, self).clean(value) 
    5567        validate_css_color_value(value) 
     68        self.value = value 
    5669        return value 
    5770 
     
    7689        # Always use own form field and widget: 
    7790        kwargs['form_class'] = ColorFormField 
     91        kwargs['widget'] = ColorInputWidget 
    7892        return super(ColorField, self).formfield(**kwargs) 
    7993