2013-07-18 21 views
3

即時通過使用靈活性在plone中創建內容類型..到目前爲止這麼好..但我想創建一個Schema.Bool,當它檢查它隱藏時一些領域。這裏是我的樣品使用z3c.form和Plone隱藏和顯示取決於其他字段值的字段

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:"), 
    ) 

我該怎麼做?請幫助

回答

2

我與Plone的網站使用這個我的小JavaScript庫這樣做:

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); 
相關問題