Plone 4敏捷视图-将CSS类添加到Fieldset X中的小部件 [英] Plone 4 dexterity viewform - add css Class to widget in fieldset X

查看:117
本文介绍了Plone 4敏捷视图-将CSS类添加到Fieldset X中的小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于灵活性的内容类型,在模式中定义了不同的编辑视图和字段集.每当我要在第一个字段集之外的另一个字段中更新小部件/字段时,它就会变得蓬松.例如:

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

必须用于在 2nd 字段集中隐藏my_field.要设置相同的字段

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

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

可以解决问题.

但是如何将CSS类添加到除第一个字段集之外的其他控件上?我的意思是

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

推荐答案

遵循

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.

相反,您可以通过Javascript来应用该类.

Instead you can apply the class via Javascript.

如果要在客户端未启用Java脚本的情况下提供备用,则可以在updateWidget()中添加条件,检查条件是否已启用,如果没有启用,则分别使用addClass()和klass-属性.那将起作用,因为所有字段均已显示且不再隐藏.

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.

这篇关于Plone 4敏捷视图-将CSS类添加到Fieldset X中的小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆