2011-05-19 53 views

回答

0

您可以設置最大和最小約束部件:

new dijit.form.TimeTextBox({ 
    name: "prog_val", 
    value: new Date(), 
    constraints: { 
     timePattern: 'HH:mm:ss', 
     clickableIncrement: 'T00:15:00', 
     visibleIncrement: 'T00:15:00', 
     visibleRange: 'T01:00:00', 
     min:'T09:00:00', 
     max:'T18:30:00' 
    } 
    }, 
    "prog_val"); 

它不允許用戶輸入的數據超出允許值。 但是,這仍然允許用戶滾動到禁用的時間,用戶不能選擇它們。

隱藏禁止時間,你應該做一些黑客:)

,你應該重寫的dijit._TimePicker_getFilteredNodes方法。例如:

dojo.declare("my._TimePicker", dijit._TimePicker, { 
       // extend the default show() method 
       _getFilteredNodes: function (/*number*/start, /*number*/maxNum, /*Boolean*/before) { 
        // summary: 
        //  Returns an array of nodes with the filter applied. At most maxNum nodes 
        //  will be returned - but fewer may be returned as well. If the 
        //  before parameter is set to true, then it will return the elements 
        //  before the given index 
        // tags: 
        //  private 
        var nodes = [], n, i = start, max = this._maxIncrement + Math.abs(i), 
       chk = before ? -1 : 1, dec = before ? 1 : 0, inc = before ? 0 : 1; 
        do { 
         i = i - dec; 
         var date = new Date(this._refDate); 
         var incrementDate = this._clickableIncrementDate; 
         date.setHours(date.getHours() + incrementDate.getHours() * i, 
        date.getMinutes() + incrementDate.getMinutes() * i, 
        date.getSeconds() + incrementDate.getSeconds() * i); 
         if (!this.isDisabledDate(date)) { 
          n = this._createOption(i); 
          if (n) { nodes.push(n); } 
         } 
         i = i + inc; 
        } while (nodes.length < maxNum && (i * chk) < max); 
        if (before) { nodes.reverse(); } 
        return nodes; 
       } 

      }); 

而且你需要設置這個新類( 'my._TimePicker')爲您的文本框時的popupClass特性:(()的函數

dojo.addOnLoad { 的dijit。 byId(「prog_val」)。popupClass =「my._TimePicker」; });

而你可以看到:it works

+0

謝謝你,我必須看看黑客選項,因爲這是我需要的。我是Zend和Dojo的新手,所以可能需要一些時間:-)我想知道max和min,但我試圖用'min'=>'T09:00:00 – Graham 2011-05-21 16:14:55