[Django] #29189: BoundField: extra css classes

7 views
Skip to first unread message

Django

unread,
Mar 5, 2018, 6:23:29 PM3/5/18
to django-...@googlegroups.com
#29189: BoundField: extra css classes
-----------------------------------------+------------------------
Reporter: James Pic | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Currently,
[https://github.com/django/django/blob/d368784bacc7e58b426f29937ee842aa14d439ad/django/forms/forms.py#L218
Form._html_output()] calls
[https://github.com/django/django/blob/d368784bacc7e58b426f29937ee842aa14d439ad/django/forms/boundfield.py#L166
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

--
Ticket URL: <https://code.djangoproject.com/ticket/29189>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 5, 2018, 6:24:47 PM3/5/18
to django-...@googlegroups.com
#29189: BoundField: extra css classes
-----------------------------+--------------------------------------

Reporter: James Pic | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by James Pic):

* cc: James Pic (added)
* type: Uncategorized => New feature


Old description:

New description:

Thanks in advance for your feedback, I can submit a patch if you want.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29189#comment:1>

Django

unread,
Mar 5, 2018, 7:36:15 PM3/5/18
to django-...@googlegroups.com
#29189: BoundField: extra css classes
-----------------------------+--------------------------------------

Reporter: James Pic | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by Tim Graham):

My initial reaction is that the `BoundField.css_classes()` method, added
in 92803205cbcaaee16ac0eb724c45019a9d896aac (#3512), is somewhat
problematic since it's only used by the `as_p()`, `as_ul()`, and
`as_table()` methods. Adding a `BoundField` attribute like
`extra_css_classes` that's only respected there doesn't seem good. Perhaps
with some more thinking we can come up with a more elegant solution.

--
Ticket URL: <https://code.djangoproject.com/ticket/29189#comment:2>

Django

unread,
Mar 5, 2018, 8:20:17 PM3/5/18
to django-...@googlegroups.com
#29189: BoundField: extra css classes
-----------------------------+--------------------------------------

Reporter: James Pic | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by James Pic):

Sure, well i think it's really necessary to limit to only one Media object
per request.
Also, you need to identify your scripts with something, ie. npm module
name+version, so you can deduplicate when 2 widgets add the same (even
with different file name because they come from different packages).
Finnaly, you need it to be able to populate itself with a Form object.

--
Ticket URL: <https://code.djangoproject.com/ticket/29189#comment:3>

Django

unread,
Mar 8, 2018, 2:40:10 PM3/8/18
to django-...@googlegroups.com
#29189: BoundField: extra css classes
-----------------------------+--------------------------------------

Reporter: James Pic | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by Tim Graham):

Could you elaborate on your proposal? I'm not sure exactly what it means.

--
Ticket URL: <https://code.djangoproject.com/ticket/29189#comment:4>

Django

unread,
Mar 8, 2018, 2:45:20 PM3/8/18
to django-...@googlegroups.com
#29189: BoundField: extra css classes
-----------------------------+--------------------------------------

Reporter: James Pic | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by James Pic):

I just don't understand how to properly override how a form field
container renders in Django ... i hoped the new forms rendering API would
help but i don't understand how ... i see many external libraries do this
... but we should probably not invest in this as there's currently a
second breath in django-adapters let's see if that's a better way to spend
our time

best regards friend

--
Ticket URL: <https://code.djangoproject.com/ticket/29189#comment:5>

Django

unread,
Mar 8, 2018, 2:50:07 PM3/8/18
to django-...@googlegroups.com
#29189: BoundField: extra css classes
-----------------------------+--------------------------------------

Reporter: James Pic | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by James Pic):

We can try to make a proposal in Django but currently in adapters the
proposal is:

{{{

# Time to show off for some user love !
assert
a.adapters.add('elementui.Form').steps.render().payload.rendered == '<an
awesome form>'

# So yeah, this kind of presentational adapters will love visiting a's
map
# and add()'s adapters the see fit !
assert
a.adapters.add('googlemdc.Form').steps.render().payload.rendered == '<an
awesome form>'

# Let's just make an HTTP response !
assert
a.adapters.add('googlemdc.Form').add('django.ProcessFormResponse').steps.process().payload.response

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29189#comment:6>

Django

unread,
Mar 22, 2018, 11:17:41 AM3/22/18
to django-...@googlegroups.com
#29189: Allow customizing the CSS classes of the <tr>, <ul>, and <p> in
Form.as_table(), as_ul(), and_p()
-----------------------------+--------------------------------------

Reporter: James Pic | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 2.0
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => wontfix


Comment:

It might be that #16922 (template based form rendering) would allow this.
Right now, I don't see a good way to implement it and the general
recommendation is not to use `as_table()`, `as_ul()`, and `as_p()` when
you have more advanced rendering requirements.

--
Ticket URL: <https://code.djangoproject.com/ticket/29189#comment:7>

Reply all
Reply to author
Forward
0 new messages