comparison app/view/widget/base/DateTimePicker.js @ 667:c34e65346572

Changes to the Datetimepicker's events, InputValidation and Sanity Checks
author Dustin Demuth <dustin@intevation.de>
date Thu, 19 Mar 2015 13:36:14 +0100
parents 195a253e9842
children 777bf66dbb11
comparison
equal deleted inserted replaced
666:7d99678fbee3 667:c34e65346572
92 } 92 }
93 ], 93 ],
94 94
95 beforeRender: function () { 95 beforeRender: function () {
96 var me = this; 96 var me = this;
97 me.hourField = new Ext.form.field.Spinner({ 97 me.hourField = new Ext.form.field.Number({
98 ownerCt: me, 98 ownerCt: me,
99 ownerLayout: me.getComponentLayout(), 99 ownerLayout: me.getComponentLayout(),
100 value: 0, 100 value: 0,
101 valueToRaw: function (value) {
102 return (value < 10 ? '0' : '') + value; // add leading Zero
103 },
101 maxValue: 23, 104 maxValue: 23,
105 maxLength: 2,
106 enforceMaxLength: true,
102 onSpinUp: function() { 107 onSpinUp: function() {
103 var value = parseInt(this.getValue()); 108 var value = parseInt(this.getValue());
104 if (value === 23) { 109 if (value === 23) {
105 return; 110 return;
106 } 111 }
107 var newValue = value + 1; 112 var newValue = value + 1;
108 if (newValue < 10) { 113 this.setValue(newValue);
109 this.setValue('0' + newValue);
110 }
111 else {
112 this.setValue(newValue);
113 }
114 }, 114 },
115 onSpinDown: function() { 115 onSpinDown: function() {
116 var value = parseInt(this.getValue()); 116 var value = parseInt(this.getValue());
117 if (value === 0) { 117 if (value === 0) {
118 return; 118 return;
119 } 119 }
120 var newValue = value - 1; 120 var newValue = value - 1;
121 if (newValue < 10) { 121 this.setValue(newValue);
122 this.setValue('0' + newValue);
123 }
124 else {
125 this.setValue(newValue);
126 }
127 }, 122 },
128 listeners: { 123 listeners: {
129 change: me.changeTimeValue, 124 change: me.changeTimeValue,
130 scope: me 125 scope: me
131 } 126 },
127 checkChangeEvents: ['change']
132 }); 128 });
133 129
134 me.minuteField = new Ext.form.field.Spinner({ 130 me.minuteField = new Ext.form.field.Number({
135 ownerCt: me, 131 ownerCt: me,
136 ownerLayout: me.getComponentLayout(), 132 ownerLayout: me.getComponentLayout(),
137 value: 0, 133 value: 0,
138 maxValue: 59, 134 maxValue: 59,
135 valueToRaw: function (value) {
136 return (value < 10 ? '0' : '') + value; // add leading Zero
137 },
138 maxLength: 2,
139 enforceMaxLength: true,
139 onSpinUp: function() { 140 onSpinUp: function() {
140 var value = parseInt(this.getValue()); 141 var value = parseInt(this.getValue());
141 if (value === 59) { 142 if (value === 59) {
142 return; 143 return;
143 } 144 }
144 var newValue = value + 1; 145 var newValue = value + 1;
145 if (newValue < 10) { 146 this.setValue(newValue);
146 this.setValue('0' + newValue);
147 }
148 else {
149 this.setValue(newValue);
150 }
151 }, 147 },
152 onSpinDown: function() { 148 onSpinDown: function() {
153 var value = parseInt(this.getValue()); 149 var value = parseInt(this.getValue());
154 if (value === 0) { 150 if (value === 0) {
155 return; 151 return;
156 } 152 }
157 var newValue = value - 1; 153 var newValue = value - 1;
158 if (newValue < 10) { 154 this.setValue(newValue);
159 this.setValue('0' + newValue);
160 }
161 else {
162 this.setValue(newValue);
163 }
164 }, 155 },
165 listeners: { 156 listeners: {
166 change: me.changeTimeValue, 157 change: me.changeTimeValue,
167 scope: me 158 scope: me
168 } 159 },
160 checkChangeEvents: ['change']
169 }); 161 });
170 162
171 me.timeLabel = new Ext.form.Label({ 163 me.timeLabel = new Ext.form.Label({
172 ownerCt: me, 164 ownerCt: me,
173 ownerLayout: me.getComponentLayout(), 165 ownerLayout: me.getComponentLayout(),
219 changeTimeValue: function (field, nValue) { 211 changeTimeValue: function (field, nValue) {
220 var value = parseInt(nValue); 212 var value = parseInt(nValue);
221 if (value > field.maxValue) { 213 if (value > field.maxValue) {
222 field.setValue(field.maxValue); 214 field.setValue(field.maxValue);
223 } 215 }
224 else if (value < 10 && (nValue.indexOf('0') !== 0 || nValue.length < 2)) { 216 if (value == null || value == "" || isNaN(value)) {
225 field.setValue('0' + nValue); 217 field.setValue('0');
226 } 218 }
227 }, 219 },
228 220
229 setValue: function(value) { 221 setValue: function(value) {
230 value.setSeconds(0); 222 value.setSeconds(0);

http://lada.wald.intevation.org