我正在使用我的小型 JavaScript 库对 Plone 站点执行此操作:
https://github.com/miohtama/jquery-interdependencies
示例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);