jensens
(Jens W. Klein)
January 26, 2017, 2:54pm
1
How do I set a class on the outer div of a form field w/o redefining the widget (iow: w/o bloating my code)?
example: I have
name = schema.TextLine(
title=u'name',
required=True,
)
I want something like:
name = schema.TextLine(
...
class="my-special-klass"
...
)
or
name = schema.TextLine(
...
)
addClass('name', "my-special-klass")
Anything I've overseen?
hvelarde
(hvelarde)
January 26, 2017, 3:40pm
2
have you tried plone.autoform directives? I think you can use something like:
from plone.autoform import directives as form
from plone.supermodel import model
....
class IMySchema(model.Schema):
form.widget('name', klass='my-special-klass')
name = schema.TextLine(
...
)
1 Like
jensens
(Jens W. Klein)
January 26, 2017, 3:59pm
3
@hvelarde Thanks, but it sets the class on the inner input
and not on the outer div
.
@jensens : Did you find a solution (or work-around) for this? I currently have the same problem and don't know how to solve it.
h2o
October 25, 2017, 4:18pm
5
I think you need to customize p.a.z3cform 's widget.pt. The readme file has some info on how to do it.
gil
(Gildardo Bautista)
February 23, 2024, 9:33pm
6
I Just found that
from plone.autoform import directives
...
directives.widget('field_name', wrapper_css_class='my-special-klass')
set a class on the outer div of a specific form field.
2 Likes
zopyx
(Andreas Jung)
February 24, 2024, 8:29am
7
Can't you use the :has()
pseudo class?
pbauer
(Philip Bauer)
February 24, 2024, 8:37am
8
Great find! That should be added to the docs.