allow string based values for comboboxarray
[roojs1] / Roo / form / MonthField.js
index 8b0c4cb..05b45f8 100644 (file)
@@ -34,15 +34,21 @@ Roo.form.MonthField = function(config){
     });
     
     
-    if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);
-    if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
+    if(typeof this.minValue == "string") {
+        this.minValue = this.parseDate(this.minValue);
+    }
+    if(typeof this.maxValue == "string") {
+        this.maxValue = this.parseDate(this.maxValue);
+    }
     this.ddMatch = null;
     if(this.disabledDates){
         var dd = this.disabledDates;
         var re = "(?:";
         for(var i = 0; i < dd.length; i++){
             re += dd[i];
-            if(i != dd.length-1) re += "|";
+            if(i != dd.length-1) {
+                re += "|";
+            }
         }
         this.ddMatch = new RegExp(re + ")");
     }
@@ -142,7 +148,7 @@ Roo.extend(Roo.form.MonthField, Roo.form.TriggerField,  {
      * {tag: "input", type: "text", size: "10", autocomplete: "off"})
      */ 
     // private
-    defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
+    defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "new-password"},
     
     // private
     hiddenField: false,
@@ -250,6 +256,10 @@ monthField.setValue('2006-5-4');
      */
     setValue : function(date){
         Roo.log('month setValue' + date);
+        // can only be first of month..
+        
+        var val = this.parseDate(date);
+        
         if (this.hiddenField) {
             this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
         }
@@ -260,12 +270,17 @@ monthField.setValue('2006-5-4');
     // private
     parseDate : function(value){
         if(!value || value instanceof Date){
+            value = value ? Date.parseDate(value.format('Y-m') + '-01', 'Y-m-d') : null;
             return value;
         }
         var v = Date.parseDate(value, this.format);
-        if (this.useIso) {
+        if (!v && this.useIso) {
             v = Date.parseDate(value, 'Y-m-d');
         }
+        if (v) {
+            // 
+            v = Date.parseDate(v.format('Y-m') +'-01', 'Y-m-d');
+        }
         
         
         if(!v && this.altFormats){
@@ -321,41 +336,53 @@ monthField.setValue('2006-5-4');
             disabledDatesRE : this.ddMatch,
             disabledDatesText : this.disabledDatesText,
             
-            format : this.format,
+            format : this.useIso ? 'Y-m-d' : this.format,
             minText : String.format(this.minText, this.formatDate(this.minValue)),
             maxText : String.format(this.maxText, this.formatDate(this.maxValue))
             
         });
-        
+         this.menu.on(Roo.apply({}, this.menuListeners, {
+            scope:this
+        }));
        
         
         var m = this.menu;
         var p = m.picker;
-        p.format = this.useIso ? 'Y-m-d' : this.format;  // make sure they are the same..?
-        Roo.log('picker set value');
-        Roo.log(this.getValue());
-        p.setValue(this.getValue() || new Date());
-        m.show(this.el, 'tl-bl?');
-        
-        // hidden the day picker
-        Roo.select('.x-date-picker table', true).first().dom.style.visibility = "hidden";
         
+        // hide month picker get's called when we called by 'before hide';
         
+        var ignorehide = true;
         p.hideMonthPicker  = function(disableAnim){
-            if(this.monthPicker){
+            if (ignorehide) {
+                return;
+            }
+             if(this.monthPicker){
+                Roo.log("hideMonthPicker called");
                 if(disableAnim === true){
                     this.monthPicker.hide();
                 }else{
                     this.monthPicker.slideOut('t', {duration:.2});
-                    p.setValue(new Date(m.picker.mpSelYear, m.picker.mpSelMonth));
+                    p.setValue(new Date(m.picker.mpSelYear, m.picker.mpSelMonth, 1));
                     p.fireEvent("select", this, this.value);
                     m.hide();
                 }
             }
         }
-        this.menu.on(  this.menuListeners, {
-                scope:this
-            });
+        
+        Roo.log('picker set value');
+        Roo.log(this.getValue());
+        p.setValue(this.getValue() ? this.parseDate(this.getValue()) : new Date());
+        m.show(this.el, 'tl-bl?');
+        ignorehide  = false;
+        // this will trigger hideMonthPicker..
+        
+        
+        // hidden the day picker
+        Roo.select('.x-date-picker table', true).first().dom.style.visibility = "hidden";
+        
+        
+        
+      
         
         p.showMonthPicker.defer(100, p);