[英]How to customize z3c.form widget for fields inside groups (fieldsets)
我有一个Plone定制控制面板注册表,我正在尝试使用一种众所周知的方法来定制zope.schema.Text
和zope.schema.TextField
一些小部件属性。
我通常以这种方式自定义updateWidgets
:
def updateWidgets(self):
super(MyEditForm, self).updateWidgets()
self.widgets['my_text_area'].style = 'width: 100%'
self.widgets['my_text_area'].rows = 7
但是现在我正在处理将字段分为两个字段集的表单:
class MySettingsEditForm(controlpanel.RegistryEditForm):
schema = IMySettingsSchema
groups = (Form1, Form2)
# fields = nothing
如果我尝试访问self.widgets['my_text_area']
我得到KeyError
。 似乎因为我没有定义fields
属性,所以无法直接访问小部件。
我发现我有groups
因此可以调用诸如self.groups[0].fields['my_text_area']
但仍然找不到访问组内字段的窗口小部件的方法。
使用组时如何自定义小部件属性?
我认为您需要使用的是小部件子窗体,请参见以下代码:
def fix_table_widget(self, name, widgets):
sub_widgets = widgets[name].widgets
for widget in sub_widgets:
new_label = widget.subform.widgets['weekday'].value
widget.subform.widgets['selected'].items[0]['label'] = new_label
widget.subform.widgets['weekday'].mode = 'hidden'
def schoolrequest_customizations(self):
''' Customizations for the schoolrequest base views
'''
for group in self.groups:
widgets = group.widgets
if 'table_bus_to_school' in widgets:
self.block_widget_table('table_bus_to_school', widgets)
self.fix_table_widget('table_bus_to_school', widgets)
if 'table_bus_to_home' in widgets:
self.block_widget_table('table_bus_to_home', widgets)
self.fix_table_widget('table_bus_to_home', widgets)
def update(self):
super(MyForm, self).update()
self.schoolrequest_customizations()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.