Changeset 9697

Show
Ignore:
Timestamp:
07/18/07 00:43:21 (18 months ago)
Author:
bill
Message:

Added a graphical _TimePicker based on the Calendar API.
Added TimeTextbox?, a slightly more general DateTextbox? with the _TimePicker as a popup widget.
DateTextbox? extends TimeTextbox?, uses a Calendar instead of a _TimePicker.
DateTextbox? uses the correct toISOString arguments to only submit the date.
Fixes #3782. Refs #599.

Code from Mark Hays (IBM, CCLA on file)

Location:
dijit/trunk
Files:
3 added
2 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/form/DateTextbox.js

    r9638 r9697  
    22 
    33dojo.require("dijit._Calendar"); 
    4 dojo.require("dijit.util.popup"); 
    5 dojo.require("dojo.date"); 
    6 dojo.require("dojo.date.locale"); 
    7 dojo.require("dojo.date.stamp"); 
    8 dojo.require("dijit.form.ValidationTextbox"); 
     4dojo.require("dijit.form.TimeTextbox"); 
    95 
    106dojo.declare( 
    117        "dijit.form.DateTextbox", 
    12         dijit.form.RangeBoundTextbox, 
     8        dijit.form.TimeTextbox, 
    139        { 
    1410                // summary: 
    1511                //              A validating, serializable, range-bound date text box. 
    16  
    17                 // constraints object: min, max 
    18                 regExpGen: dojo.date.locale.regexp, 
    19                 compare: dojo.date.compare, 
    20                 format: dojo.date.locale.format, 
    21                 parse: dojo.date.locale.parse, 
    22                 value: new Date(), 
    23  
     12                 
     13                _popupClass: "dijit._Calendar", 
     14                 
    2415                postMixInProperties: function(){ 
    25                         dijit.form.RangeBoundTextbox.prototype.postMixInProperties.apply(this, arguments); 
     16                        this.inherited('postMixInProperties', arguments); 
    2617 
    2718                        // #3407: only change constraints after postMixInProperties or ValidationTextbox will clear the change 
    2819                        this.constraints.selector = 'date'; 
    29          
    30                         // #2999 
    31                         if(typeof this.constraints.min == "string"){ this.constraints.min = dojo.date.stamp.fromISOString(this.constraints.min); } 
    32                         if(typeof this.constraints.max == "string"){ this.constraints.max = dojo.date.stamp.fromISOString(this.constraints.max); } 
    33                 }, 
    34  
    35                 onfocus: function(/*Event*/ evt){ 
    36                         // open the calendar 
    37                         this._open(); 
    38                         dijit.form.RangeBoundTextbox.prototype.onfocus.apply(this, arguments); 
    39                 }, 
    40  
    41                 serialize: function(/*Date*/date){ 
    42                         return dojo.date.stamp.toISOString(date, 'date'); // String 
    43                 }, 
    44  
    45                 setValue: function(/*Date*/date, /*Boolean, optional*/ priorityChange){ 
    46                         // summary: 
    47                         //      Sets the date on this textbox 
    48                         this.inherited('setValue', arguments); 
    49                         if(this._calendar){ 
    50                                 this._calendar.setValue(date); 
    51                         } 
    52                 }, 
    53  
    54                 _open: function(){ 
    55                         // summary: 
    56                         //      opens the Calendar, and sets the onValueSelected for the Calendar 
    57                         var self = this; 
    58  
    59                         if(!this._calendar){ 
    60                                 this._calendar = new dijit._Calendar({ 
    61                                         onValueSelected: function(value){ 
    62  
    63                                                 self.focus(); // focus the textbox before the popup closes to avoid reopening the popup 
    64                                                 setTimeout(dijit.util.popup.close, 1); // allow focus time to take 
    65  
    66                                                 // this will cause InlineEditBox and other handlers to do stuff so make sure it's last 
    67                                                 dijit.form.DateTextbox.superclass.setValue.call(self, value, true); 
    68                                         }, 
    69                                         lang: this.lang, 
    70                                         isDisabledDate: function(/*Date*/ date){ 
    71                                                 // summary: 
    72                                                 //      disables dates outside of the min/max of the DateTextbox 
    73                                                 return self.constraints && (dojo.date.compare(self.constraints.min,date) > 0 || dojo.date.compare(self.constraints.max,date) < 0); 
    74                                         } 
    75                                 }); 
    76                                 this._calendar.setValue(this.getValue() || new Date()); 
    77                         } 
    78                         if(!this._opened){ 
    79                                 dijit.util.popup.open({ 
    80                                         host: this, 
    81                                         popup: this._calendar, 
    82                                         around: this.domNode, 
    83                                         onClose: function(){ self._opened=false; } 
    84                                 }); 
    85                                 this._opened=true; 
    86                         } 
    87                 }, 
    88  
    89                 _onBlur: function(){ 
    90                         // summary: called magically when focus has shifted away from this widget and it's dropdown 
    91                         dijit.util.popup.closeAll(); 
    92                         this.inherited('_onBlur', arguments); 
    93                         // don't focus on <input>.  the user has explicitly focused on something else. 
    94                 }, 
    95  
    96                 postCreate: function(){ 
    97                         this.inherited('postCreate', arguments); 
    98                         this.connect(this.domNode, "onclick", this._open); 
    99                 }, 
    100  
    101                 getDisplayedValue:function(){ 
    102                         return this.textbox.value; 
    103                 }, 
    104  
    105                 setDisplayedValue:function(/*String*/ value){ 
    106                         this.textbox.value=value; 
    10720                } 
    10821        } 
  • dijit/trunk/tests/form/test_validate.html

    r9627 r9697  
    1515                        dojo.require("dijit.form.CurrencyTextbox"); 
    1616                        dojo.require("dijit.form.DateTextbox"); 
     17                        dojo.require("dijit.form.TimeTextbox"); 
    1718//                      dojo.require("dojo.validate.common"); 
    1819//                      dojo.require("dojo.validate.us"); 
     
    407408        </div> 
    408409        <div class="testExample"> 
    409                 <input id="q16" type="text" name="time1" class="medium" value="5:45:00 pm" 
    410                         dojoType="dijit.form.ValidationTextbox" 
    411                         validator="dojo.date.locale.parse" 
     410                <input id="q16" type="text" name="time1" class="medium" value="T17:45:00" 
     411                        dojoType="dijit.form.TimeTextbox" 
    412412                        constraints={formatLength:'medium',selector:'time'} 
    413                         trim="true" 
    414413                        required="true" 
    415414                        invalidMessage="Invalid time." /> 
     
    422421        </div> 
    423422        <div class="testExample"> 
    424                 <input id="q17" type="text" name="time2" class="medium" value="17:45:00" 
    425                         dojoType="dijit.form.ValidationTextbox" 
    426                         validator="dojo.date.locale.parse" 
     423                <input id="q17" type="text" name="time2" class="medium" value="T17:45:00" 
     424                        dojoType="dijit.form.TimeTextbox" 
    427425                        constraints={formatLength:'short',selector:'time',timePattern:'HH:mm:ss'} 
    428                         trim="true" 
    429426                        required="true" 
    430427                        invalidMessage="Invalid time. Use HH:mm:ss where HH is 00 - 23 hours.">