3

我使用灵巧在 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:"),
    )

我怎样才能做到这一点??请帮忙

4

1 回答 1

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);
于 2013-07-18T06:40:47.317 回答