[Lada-commits] [PATCH] Fix and complement validation of Messprogramm from

Wald Commits scm-commit at wald.intevation.org
Thu Oct 13 14:43:13 CEST 2016


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1476362546 -7200
# Node ID 3e6756b0fc97568f0b7255fb84d76347fc7ef6b9
# Parent  85b018980347909a866389e7dc3619ec82fbcad3
Fix and complement validation of Messprogramm from.

diff -r 85b018980347 -r 3e6756b0fc97 app/view/form/Messprogramm.js
--- a/app/view/form/Messprogramm.js	Tue Oct 11 17:40:37 2016 +0200
+++ b/app/view/form/Messprogramm.js	Thu Oct 13 14:42:26 2016 +0200
@@ -115,7 +115,10 @@
                                 labelWidth: 95,
                                 allowBlank: false,
                                 editable: true,
-                                hidden: true
+                                hidden: true,
+                                listeners: {
+                                    validitychange: me.mstLaborValidity
+                                }
                             }, {
                                 xtype: 'messstelle',
                                 name: 'laborMstId',
@@ -125,7 +128,10 @@
                                 labelWidth: 95,
                                 allowBlank: false,
                                 editable: true,
-                                hidden: true
+                                hidden: true,
+                                listeners: {
+                                    validitychange: me.mstLaborValidity
+                                }
                             }, {
                                 xtype: 'netzbetreiber',
                                 name: 'netzbetreiberId',
@@ -482,6 +488,17 @@
         i.setMaxValue(max-1);
     },
 
+    /*
+     * Set validity of messstellelabor field (not part of the form) based
+     * on validitychange event of hidden mstId and laborMstId
+     */
+    mstLaborValidity: function(field, isValid) {
+        if (!isValid) {
+            field.up('fieldset').down('messstellelabor')
+                .down('combobox').markInvalid('');
+        }
+    },
+
     setRecord: function(messRecord) {
         this.clearMessages();
         this.getForm().loadRecord(messRecord);
diff -r 85b018980347 -r 3e6756b0fc97 app/view/widget/DayOfYear.js
--- 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();
diff -r 85b018980347 -r 3e6756b0fc97 app/view/widget/base/ComboBox.js
--- a/app/view/widget/base/ComboBox.js	Tue Oct 11 17:40:37 2016 +0200
+++ b/app/view/widget/base/ComboBox.js	Thu Oct 13 14:42:26 2016 +0200
@@ -69,6 +69,9 @@
             hidden: true
         }];
         this.callParent(arguments);
+        /* listeners have been passed to combobox. Thus, clear them on panel
+         * to avoid double effects of events fired on combobox and panel. */
+        this.clearListeners();
     },
 
     showWarnings: function(warnings) {
diff -r 85b018980347 -r 3e6756b0fc97 app/view/window/Messprogramm.js
--- a/app/view/window/Messprogramm.js	Tue Oct 11 17:40:37 2016 +0200
+++ b/app/view/window/Messprogramm.js	Thu Oct 13 14:42:26 2016 +0200
@@ -176,6 +176,7 @@
             this.down('messmethodengrid').setReadOnly(true);
             this.down('messprogrammform').setRecord(record);
         }
+        this.down('messprogrammform').isValid();
     },
 
     //This was used in a Probewindow, I left it here for reference...


More information about the Lada-commits mailing list