Opened 7 years ago

Last modified 7 years ago

#29189 closed New feature

BoundField: extra css classes — at Initial Version

Reported by: James Pic Owned by: nobody
Component: Forms Version: 2.0
Severity: Normal Keywords:
Cc: James Pic Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, Form._html_output() calls BoundField.css_classes() to get the list of classes to apply on the field container, such as error_css_class or required_css_class.

My objective is something like :

form['myfield'].extra_css_classes = 'hide'

(Setting the class in JS too, but this causes a flash of course)

Could we perhaps allow adding extra css classes to BoundField ?

Currently I have this little hack which works but isn't doing anything that's supposed to be supported so please bare with me, it's just here to serve as an example and attempt to illustrate what I would like to get rid of in my own code:

class BoundField(forms.BoundField):
    """BoundField override for facond Form."""

    def css_classes(self):
        """Allow setting extra_css_classes."""
        return super(BoundField, self).css_classes(
            getattr(self, 'extra_css_classes', ''))

class Form(forms.Form):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():  
            # not sure what it breaks to instanciate BoundFields here
            # rather than in __getitem__
            self._bound_fields_cache[name] = BoundField(self, field, name)

Thanks in advance for your feedback

Change History (0)

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