Hi,

Please find attached patch for numeric control with optionally allow null
values

Null values: undefined/empty string/null
By default numeric control value can not be null. Use flag *allowNull: true*
to allow null values.

Usage:

id: 'fillfactor', label: '{{ _('Fill factor') }}', deps: ['index'],
type: 'numeric', group: '{{ _('Definition') }}', allowNull: true,



-- 
*Harshal Dhumal*
*Software Engineer *



EenterpriseDB <http://www.enterprisedb.com>
diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js
index 4346156..82963bb 100644
--- a/web/pgadmin/static/js/backform.pgadmin.js
+++ b/web/pgadmin/static/js/backform.pgadmin.js
@@ -1333,49 +1333,56 @@
     checkNumeric: function(e) {
       var field = _.defaults(this.field.toJSON(), this.defaults),
           attrArr = this.field.get("name").split('.'),
+          allowNull = this.field.get("allowNull"),
           name = attrArr.shift(),
           value = this.getValueFromDOM(),
           min_value = field.min,
           max_value = field.max,
           isValid = true,
-          intPattern = new RegExp("^-?[0-9]+(\.?[0-9]*)?$"),
-          isMatched = intPattern.test(value);
+          intPattern = new RegExp("^-?[0-9]+(\.?[0-9]*)?$");
 
-      // Below logic will validate input
-      if (!isMatched) {
-        isValid = false;
-        this.model.errorModel.unset(name);
-        this.model.errorModel.set(
-            name,
-            S(pgAdmin.Browser.messages.MUST_BE_NUM).sprintf(
-              field.label
-              ).value()
-            );
-      }
+      if (allowNull && (_.isUndefined(value) ||
+           _.isNull(value) || value == '')) {
+        // Check for undefined/empty/null value if it's allowed.
+        value = null;
+      } else {
+        var isMatched = intPattern.test(value);
+        // Below logic will validate input
+        if (!isMatched) {
+          isValid = false;
+          this.model.errorModel.unset(name);
+          this.model.errorModel.set(
+              name,
+              S(pgAdmin.Browser.messages.MUST_BE_NUM).sprintf(
+                field.label
+                ).value()
+              );
+        }
 
-      // Below will check if entered value is in-between min & max range
-      if (isValid && (!_.isUndefined(min_value) && value < min_value)) {
-        isValid = false;
-        this.model.errorModel.unset(name);
-        this.model.errorModel.set(
-            name,
-            S(pgAdmin.Browser.messages.MUST_GR_EQ).sprintf(
-              field.label,
-              min_value
-              ).value()
-            );
-      }
+        // Below will check if entered value is in-between min & max range
+        if (isValid && (!_.isUndefined(min_value) && value < min_value)) {
+          isValid = false;
+          this.model.errorModel.unset(name);
+          this.model.errorModel.set(
+              name,
+              S(pgAdmin.Browser.messages.MUST_GR_EQ).sprintf(
+                field.label,
+                min_value
+                ).value()
+              );
+        }
 
-      if (isValid && (!_.isUndefined(max_value) && value > max_value)) {
-        isValid = false;
-        this.model.errorModel.unset(name);
-        this.model.errorModel.set(
-            name,
-            S(pgAdmin.Browser.messages.MUST_LESS_EQ).sprintf(
-              field.label,
-              max_value
-              ).value()
-            );
+        if (isValid && (!_.isUndefined(max_value) && value > max_value)) {
+          isValid = false;
+          this.model.errorModel.unset(name);
+          this.model.errorModel.set(
+              name,
+              S(pgAdmin.Browser.messages.MUST_LESS_EQ).sprintf(
+                field.label,
+                max_value
+                ).value()
+              );
+        }
       }
 
       // After validation we need to set that value into model (only if all flags are true)
-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to