diff app/view/widget/DayOfYear.js @ 1212:3e6756b0fc97

Fix and complement validation of Messprogramm from.
author Tom Gottfried <tom@intevation.de>
date Thu, 13 Oct 2016 14:42:26 +0200
parents 85b018980347
children 01f083db45b7
line wrap: on
line diff
--- a/app/view/widget/DayOfYear.js	Tue Oct 11 17:40:37 2016 +0200
+++ b/app/view/widget/DayOfYear.js	Thu Oct 13 14:42:26 2016 +0200
@@ -71,11 +71,13 @@
         var DOYField = Ext.create('Ext.form.field.Number', {
             name: this.name,
             hidden: true,
+            allowBlank: this.allowBlank,
             listeners: this.listeners
         });
         /* Use dirtychange to avoid endless loop with change listeners on
          * visible items. This one is for initialisation by the form. */
         DOYField.addListener('dirtychange', me.setFields);
+        DOYField.addListener('validitychange', me.validityChange);
 
         /*
          * Add hidden field and visible fields to let the user choose
@@ -166,15 +168,16 @@
         var month = panel.down('combobox').getValue();
         var day = panel.down('numberfield[hidden=false]').getValue();
         var maxDay = panel.down('numberfield[hidden=false]').maxValue;
+        var doy = null;
 
         if (month != null && day != null && day <= maxDay) {
             // create a date object with arbitrary non-leap year
             var date = new Date(1970, month, day);
 
             // day of year is 0-based in ExtJS, but 1-based in the model
-            var doy = Ext.Date.getDayOfYear(date) + 1;
-            panel.down('numberfield[hidden]').setValue(doy);
+            doy = Ext.Date.getDayOfYear(date) + 1;
         }
+        panel.down('numberfield[hidden]').setValue(doy);
     },
 
     /*
@@ -182,9 +185,6 @@
      * validate associated day value.
      */
     checkMaxDay: function() {
-        this.up('panel').down('numberfield[hidden=false]')
-            .clearInvalid();
-
         // create a date object with arbitrary non-leap year
         var maxDay = Ext.Date.getDaysInMonth(
             new Date(1970, this.getValue()));
@@ -193,9 +193,13 @@
 
         var curDay = this.up('panel')
             .down('numberfield[hidden=false]').getValue();
-        if (curDay > maxDay) {
+        if (curDay) {
+            if (curDay > maxDay) {
+                this.up('panel').down('numberfield[hidden=false]')
+                    .setValue(maxDay);
+            }
             this.up('panel').down('numberfield[hidden=false]')
-                .setValue(maxDay);
+                .clearInvalid();
         }
     },
 
@@ -238,6 +242,22 @@
         }
     },
 
+    /*
+     * When the hidden field is validated as part of a form, make the result
+     * user visible.
+     */
+    validityChange: function(field, isValid) {
+        if (!isValid) {
+            var errors = field.getActiveErrors()
+            field.up('panel').down('combobox').markInvalid(errors);
+            field.up('panel').down('numberfield[hidden=false]')
+                .markInvalid(errors);
+        } else {
+            field.up('panel').down('combobox').clearInvalid();
+            field.up('panel').down('numberfield[hidden=false]').clearInvalid();
+        }
+    },
+
     clearWarningOrError: function() {
         this.down('image[name=errorImg]').hide();
         this.down('image[name=warnImg]').hide();

http://lada.wald.intevation.org