source: Dev/trunk/src/client/dojox/form/MonthTextBox.js @ 532

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

Added Dojo 1.9.3 release.

File size: 1.9 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dojo/_base/lang",
4        "dojox/widget/MonthlyCalendar",
5        "dijit/form/TextBox",
6        "./DateTextBox",
7        "dojo/_base/declare"
8        ], function(kernel, lang, MonthlyCalendar, TextBox, DateTextBox, declare){
9                kernel.experimental("dojox/form/DateTextBox");
10                return declare( "dojox.form.MonthTextBox", DateTextBox,
11                {
12                        // summary:
13                        //              A validating, serializable, range-bound date text box with a popup calendar that contains only months
14
15                        // popupClass: String
16                        //              The popup widget to use. In this case, a calendar with just a Month view.
17                        popupClass: MonthlyCalendar,
18
19                        selector: "date",
20
21                        postMixInProperties: function(){
22                                this.inherited(arguments);
23                                this.constraints.datePattern = "MM";
24                        },
25
26                        format: function(value){
27                                if(!value && value !== 0){
28                                        return 1;
29                                }
30                                if(value.getMonth){
31                                        return value.getMonth() + 1;
32                                }
33                                return Number(value) + 1;
34                        },
35
36                        parse: function(value, constraints){
37                                return Number(value) - 1;
38                        },
39
40                        serialize: function(value, constraints){
41                                return String(value);
42                        },
43
44                        validator: function(value){
45                                var num = Number(value);
46                                var isInt = /(^-?\d\d*$)/.test(String(value));
47                                return value == "" || value == null || (isInt && num >= 1 && num <= 12);
48                        },
49
50                        _setValueAttr: function(value, priorityChange, formattedValue){
51                                if(value){
52                                        if(value.getMonth){
53                                                value = value.getMonth();
54                                        }
55                                }
56                                TextBox.prototype._setValueAttr.call(this, value, priorityChange, formattedValue);
57                        },
58
59                        openDropDown: function(){
60                                this.inherited(arguments);
61
62                                this.dropDown.onValueSelected = lang.hitch(this, function(value){
63                                        this.focus(); // focus the textbox before the popup closes to avoid reopening the popup
64                                        setTimeout(lang.hitch(this, "closeDropDown"), 1); // allow focus time to take
65                                        TextBox.prototype._setValueAttr.call(this, value, true, value);
66                                });
67                        }
68                });
69});
Note: See TracBrowser for help on using the repository browser.