Made DateTimeField implementation for Gilbert more naive to avoid confusing autofill...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Thu, 7 Apr 2011 16:20:54 +0000 (12:20 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Thu, 7 Apr 2011 16:20:54 +0000 (12:20 -0400)
contrib/gilbert/media/gilbert/lib/ui/forms.js

index 719b7b1..ca7f4e6 100644 (file)
@@ -322,7 +322,7 @@ Gilbert.lib.ui.DateTimeField = Ext.extend(Ext.form.Field, {
                // render DateField and TimeField
                // create bounding table
                var t;
                // render DateField and TimeField
                // create bounding table
                var t;
-               if ('below' === this.timePosition || 'bellow' === this.timePosition) {
+               if ('below' === this.timePosition) {
                        t = Ext.DomHelper.append(ct, {
                                tag: 'table',
                                style: 'border-collapse:collapse',
                        t = Ext.DomHelper.append(ct, {
                                tag: 'table',
                                style: 'border-collapse:collapse',
@@ -582,7 +582,18 @@ Gilbert.lib.ui.DateTimeField = Ext.extend(Ext.form.Field, {
         */
        ,
        isValid: function() {
         */
        ,
        isValid: function() {
-               return this.df.isValid() && this.tf.isValid();
+               var valid = true;
+               var msg = "Both fields must be supplied."
+               if (!(this.df.isValid() && this.tf.isValid())) valid = false;
+               if (Boolean(this.df.getValue()) != Boolean(this.tf.getValue())) {
+                       valid = false;
+                       if (!this.df.getValue()){
+                               if (!(this.tf.hasFocus || this.df.hasFocus)) this.df.markInvalid(msg);
+                       } else {
+                               if (!(this.tf.hasFocus || this.df.hasFocus)) this.tf.markInvalid(msg);
+                       };
+               };
+               return valid;
        }
        // eo function isValid
        // }}}
        }
        // eo function isValid
        // }}}
@@ -838,9 +849,6 @@ Gilbert.lib.ui.DateTimeField = Ext.extend(Ext.form.Field, {
                if (d) {
                        if (! (this.dateValue instanceof Date)) {
                                this.initDateValue();
                if (d) {
                        if (! (this.dateValue instanceof Date)) {
                                this.initDateValue();
-                               if (!this.tf.getValue()) {
-                                       this.setTime(this.dateValue);
-                               }
                        }
                        this.dateValue.setMonth(0);
                        // because of leap years
                        }
                        this.dateValue.setMonth(0);
                        // because of leap years
@@ -850,7 +858,6 @@ Gilbert.lib.ui.DateTimeField = Ext.extend(Ext.form.Field, {
                }
                else {
                        this.dateValue = '';
                }
                else {
                        this.dateValue = '';
-                       this.setTime('');
                }
        }
        // eo function updateDate
                }
        }
        // eo function updateDate
@@ -868,7 +875,6 @@ Gilbert.lib.ui.DateTimeField = Ext.extend(Ext.form.Field, {
                }
                if (t && !this.df.getValue()) {
                        this.initDateValue();
                }
                if (t && !this.df.getValue()) {
                        this.initDateValue();
-                       this.setDate(this.dateValue);
                }
                if (this.dateValue instanceof Date) {
                        if (t) {
                }
                if (this.dateValue instanceof Date) {
                        if (t) {
@@ -919,7 +925,18 @@ Gilbert.lib.ui.DateTimeField = Ext.extend(Ext.form.Field, {
         */
        ,
        validate: function() {
         */
        ,
        validate: function() {
-               return this.df.validate() && this.tf.validate();
+               var valid = true;
+               var msg = "Both fields must be supplied."
+               if (!(this.df.validate() && this.tf.validate())) valid = false;
+               if (Boolean(this.df.getValue()) != Boolean(this.tf.getValue())) {
+                       valid = false;
+                       if (!this.df.getValue()){
+                               if (!(this.tf.hasFocus || this.df.hasFocus)) this.df.markInvalid(msg);
+                       } else {
+                               if (!(this.tf.hasFocus || this.df.hasFocus)) this.tf.markInvalid(msg);
+                       };
+               };
+               return valid;
        }
        // eo function validate
        // }}}
        }
        // eo function validate
        // }}}