Plone 4 dexterity viewform - add css Class to widget in fieldset X

梦想的初衷 提交于 2019-12-08 01:55:15

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/15385575/plone-4-dexterity-viewform-add-css-class-to-widget-in-fieldset-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!