Question

I have a dexterity based content type with different edit views and fieldsets defined in the schema. Whenever I want to update a widget/field in another than the first fieldset, it gets crumpy. For example:

self.groups[0].fields['my_field'].mode = HIDDEN_MODE

must be used to hide my_field from the 2nd fieldset. To make the same field required

self.schema['my_field'].required = True

does the trick.

But how can I add a css class to a widget on another than the first fieldset? I mean, what

self.fields['my_field_on_first_fieldset'].widget.addClass("myClass")

would do, if my widget would be on the first fieldset "page".

Was it helpful?

Solution

Following Martin Aspeli's tutorial, I tested your request and can confirm that oddly the klass-attribute cannot be applied on invisible widgets in the sub-fieldsets, returning a 'Key Error' in reference to the widget's name.

With other attributes, f.e. 'size', there is no problem.

Instead you can apply the class via Javascript.

If you want to provide a fallback in case the client hasn't Javascript enabled, you can add a condition in updateWidget(), checking if it is enabled and if not, apply the class with addClass() respectively the klass-attribute. Which will work then, because all fields are shown and not hidden anymore.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top