我正在使用灵巧创建plone中的内容类型..到目前为止很好..但我想创建一个Schema.Bool,当它检查它隐藏一些字段。这是我的样本
sameaddress = schema.Bool(
title=_(u"Sames as bill to address"),
required=False,
)
toCustShipStreet = schema.TextLine(
title=_(u"Ship to - Street:"),
)
toCustShipCity = schema.TextLine(
title=_(u"Ship to - City:"),
)
toCustShipState = schema.TextLine(
title=_(u"Ship to - State:"),
)
toCustShipCountry = schema.TextLine(
title=_(u"Ship to - Country:"),
)
我该怎么做?请帮忙
答案 0 :(得分:2)
我使用这个我的小JavaScript库在Plone网站上这样做:
https://github.com/miohtama/jquery-interdependencies
将deps.js嵌入为JavaScript资源
创建一个控制器文件,用于定义布尔字段隐藏的小部件以及诸如此类的内容(这实际上不是Plone特定的,您可以输入任何CSS ID)
确保每次加载正确的页面时都会触发逻辑
示例widget-rules.js
(出于保密原因,我无法提供完整的示例,但这应该给你一些指示):
/*global console*/
(function($) {
"use strict";
// jQuery selector for all possible different stenosis fields (CR, MR, treatment)
var stenosisFields = "#formfield-thrombectomyVariables-widgets-thrombectomyVariables_treatmentSpecifylocalizationOfStenosis";
function log(msg) {
if(console && console.log) {
console.log(msg);
}
}
/**
* Generate datagridfield block jQuery class selection based on field name.
*
* Note that the same field will appear multiple times on the page.
*/
function getDGFId(fname) {
return ".datagridwidget-widget-" + fname;
}
function buildRules() {
// Start creating a new ruleset
var ruleset = $.deps.createRuleset();
var masterSwitch = ruleset.createRule("#typeOfStenosisOcclusion") + " select", "==", "other");
// Make this controls to be slave for the master rule
masterSwitch.include("#typeOfStenosisOcclusionWhich");
return ruleset;
}
function init() {
// Master field containing all MTD rows
var fields = $(stenosisFields);
if(fields.size() > 0) {
var ruleset = buildRules();
initRules($this, ruleset);
followRules($this, ruleset);
}
}
$(document).bind("ready", init);
})(jQuery);