2010-05-19 5 views
1

사용자가 날짜를 & 시간으로 지정할 수있는 Dojo 위젯을 작성해야합니다. Dojo 버그 추적기의 항목에 첨부 된 샘플 구현을 발견했습니다. 모양이 좋고 대부분 작동하지만 양식을 제출할 때 클라이언트가 보낸 값은 사용자가 선택한 값이 아니라 서버에서 보낸 값입니다.My Dijit DateTimeCombo 위젯이 양식 제출시 선택된 값을 보내지 않습니다.

& 시간 값을 제출할 위젯을 얻으려면 어떤 변경이 필요합니까?

샘플 사용 기본 HTML 태그 (형태 & 입력)와 JSP 렌더링하는 다음 는 ID로 기본 요소를 선택하는 기능을 dojo.addOnLoad) (dojoType 특성 및 dojo.parser.parse 추가 - 페이지.

미리 감사드립니다.

위젯은 두 개의 파일로 구현됩니다. 응용 프로그램은 Dojo 1.3을 사용합니다.

파일 1 : DateTimeCombo.js

dojo.provide("dojox.form.DateTimeCombo"); 

dojo.require("dojox.form._DateTimeCombo"); 
dojo.require("dijit.form._DateTimeTextBox"); 

dojo.declare(
    "dojox.form.DateTimeCombo", 
    dijit.form._DateTimeTextBox, 
    { 
     baseClass: "dojoxformDateTimeCombo dijitTextBox", 
     popupClass: "dojox.form._DateTimeCombo", 
     pickerPostOpen: "pickerPostOpen_fn",   
     _selector: 'date',  
     constructor: function (argv) {}, 

     postMixInProperties: function() 
     {    
      dojo.mixin(this.constraints, { 
       /* 
       datePattern: 'MM/dd/yyyy HH:mm:ss', 
       timePattern: 'HH:mm:ss', 
       */ 
       datePattern: 'MM/dd/yyyy HH:mm', 
       timePattern: 'HH:mm', 

       clickableIncrement:'T00:15:00', 
       visibleIncrement:'T00:15:00', 
       visibleRange:'T01:00:00' 
      }); 
      this.inherited(arguments); 
     }, 

    _open: function() 
    { 
     this.inherited(arguments); 
     if (this._picker!==null && (this.pickerPostOpen!==null && this.pickerPostOpen!=="")) 
     { 
      if (this._picker.pickerPostOpen_fn!==null) 
      { 
       this._picker.pickerPostOpen_fn(this); 
      } 
     } 
    }  

    } 
); 

파일 2 : _DateTimeCombo.js

dojo.provide("dojox.form._DateTimeCombo"); 

dojo.require("dojo.date.stamp"); 
dojo.require("dijit._Widget"); 
dojo.require("dijit._Templated"); 
dojo.require("dijit._Calendar"); 
dojo.require("dijit.form.TimeTextBox"); 
dojo.require("dijit.form.Button"); 

dojo.declare("dojox.form._DateTimeCombo", 
    [dijit._Widget, dijit._Templated], 
{ 

    // invoked only if time picker is empty 
    defaultTime: function() { 
     var res= new Date(); 
     res.setHours(0,0,0); 
     return res; 
    }, 

    // id of this table below is the same as this.id 
    templateString: 
    " <table class=\"dojoxDateTimeCombo\" waiRole=\"presentation\">\ 
     <tr class=\"dojoxTDComboCalendarContainer\">\ 
     <td>\ 
      <center><input dojoAttachPoint=\"calendar\" dojoType=\"dijit._Calendar\"></input></center>\ 
     </td>\ 
     </tr>\ 
     <tr class=\"dojoxTDComboTimeTextBoxContainer\">\ 
     <td>\ 
      <center><input dojoAttachPoint=\"timePicker\" dojoType=\"dijit.form.TimeTextBox\"></input></center>\ 
     </td>\ 
     </tr>\ 
     <tr><td><center><button dojoAttachPoint=\"ctButton\" dojoType=\"dijit.form.Button\">Ok</button></center></td></tr>\ 
     </table>\ 
    ", 

    widgetsInTemplate: true, 

    constructor: function(arg) {}, 

    postMixInProperties: function() {  
     this.inherited(arguments);  
    }, 

    postCreate: function() { 
     this.inherited(arguments); 
     this.connect(this.ctButton, "onClick", "_onValueSelected"); 
    }, 

    // initialize pickers to calendar value 
    pickerPostOpen_fn: function (parent_inst) { 
     var parent_value = parent_inst.attr('value'); 
     if (parent_value !== null) { 
      this.setValue(parent_value); 
     } 
    }, 

    // expects a valid date object 
    setValue: function(value) { 
     if (value!==null) { 
      this.calendar.attr('value', value); 
      this.timePicker.attr('value', value); 
     }  
    }, 

    // return a Date constructed date in calendar & time in time picker. 
    getValue: function() { 
     var value = this.calendar.attr('value'); 
     var result=value;  
     if (this.timePicker.value !== null) { 
      if ((this.timePicker.value instanceof Date) === true) { 
       result.setHours(this.timePicker.value.getHours(), 
       this.timePicker.value.getMinutes(), 
       this.timePicker.value.getSeconds()); 
       return result; 
      } 
     } else { 
      var defTime=this.defaultTime(); 
      result.setHours(defTime.getHours(), 
       defTime.getMinutes(), 
       defTime.getSeconds()); 
      return result;     
     } 
    }, 

    _onValueSelected: function() { 
     var value = this.getValue(); 
     this.onValueSelected(value); 
    }, 

    onValueSelected: function(value) {} 

}); 

답변

0

당신이 getValue을 사용할 것 소리. 컨벤션은 이제 _getValueAttr을 사용하고 attr ("value")를 호출하지만 Dojo 1.4에서 시작되었으며이 코드는이 새로운 패턴을 사용하기 위해 이식되어야한다고 생각한다.

값은 가장 내가 DateTimeCombo에 "직렬화"방법을 추가 한 후이 잘 작동하기 시작했다

0

dojo.date.stamp.toISOString를 사용하여 서버()에 전송되는 자바 스크립트 Date 객체를해야한다 노 있음 .js 정확히 원하는 출력 형식을 빌드합니다.

_DateTimeTextBox.js에 필요한 ISO 형식으로 값을 출력해야하는 serialize 구현이 이미 있기 때문에 이상하게 보입니다.

관련 문제