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.
* 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>
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>
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>
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>
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>
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>
* 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>