source: Dev/trunk/src/client/dojox/form/YearTextBox.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.8 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dojo/_base/lang",
4        "dojox/widget/YearlyCalendar",
5        "dijit/form/TextBox",
6        "./DateTextBox",
7        "dojo/_base/declare"
8        ], function(kernel, lang, YearlyCalendar, TextBox, DateTextBox, declare){
9                kernel.experimental("dojox/form/DateTextBox");
10                return declare("dojox.form.YearTextBox", DateTextBox,
11                {
12                        // summary:
13                        //              A validating, serializable, range-bound date text box with a popup calendar that contains only years
14
15                        popupClass: YearlyCalendar,
16
17                        format: function(value){
18                                //console.log('Year format ' + value);
19                                if(typeof value == "string"){
20                                        return value;
21                                }
22                                else if(value.getFullYear){
23                                        return value.getFullYear();
24                                }
25                                return value;
26                        },
27
28                        validator: function(value){
29                                return value == "" || value == null || /(^-?\d\d*$)/.test(String(value));
30                        },
31
32                        _setValueAttr: function(value, priorityChange, formattedValue){
33                                if(value){
34                                        if(value.getFullYear){
35                                                value = value.getFullYear();
36                                        }
37                                }
38                                TextBox.prototype._setValueAttr.call(this, value, priorityChange, formattedValue);
39                        },
40
41                        openDropDown: function(){
42                                this.inherited(arguments);
43                                //console.log('yearly openDropDown and value = ' + this.get('value'));
44
45                                this.dropDown.onValueSelected = lang.hitch(this, function(value){
46                                        this.focus(); // focus the textbox before the popup closes to avoid reopening the popup
47                                        setTimeout(lang.hitch(this, "closeDropDown"), 1); // allow focus time to take
48                                        TextBox.prototype._setValueAttr.call(this,value, true, value);
49                                });
50                        },
51
52                        parse: function(/*String*/ value, /*dojo.date.locale.__FormatOptions*/ constraints){
53                                return value || (this._isEmpty(value) ? null : undefined); // Date
54                        },
55
56                        filter: function(val){
57                                if(val && val.getFullYear){
58                                        return val.getFullYear().toString();
59                                }
60                                return this.inherited(arguments);
61                        }
62                });
63});
Note: See TracBrowser for help on using the repository browser.