add class/instance methods for checking required-ness and validity of an object field...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 2 Jun 2010 15:11:52 +0000 (15:11 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 2 Jun 2010 15:11:52 +0000 (15:11 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16557 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js
Open-ILS/web/js/dojo/fieldmapper/IDL.js

index da16e20..4d4f9c3 100644 (file)
@@ -69,7 +69,26 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){
                                }
                        }
                        return obj;
-               }
+               },
+
+        RequiredField : function (f) {
+            if (!f) return;
+            if (fieldmapper.IDL && fieldmapper.IDL.loaded)
+                return this.Structure.fields[f].required;
+            return;
+        },
+
+        ValidateField : function (f) {
+            if (!f) return;
+            if (fieldmapper.IDL && fieldmapper.IDL.loaded) {
+                if (this.Structure.fields[f] && this.Structure.fields[f].validate) {
+                    return this.Structure.fields[f].validate.test(this[f]());
+                }
+                return true;
+            }
+            return;
+        }
+            
 
  
 /*
index b0ee5ea..17fcdff 100644 (file)
@@ -81,8 +81,8 @@ if(!dojo._hasResource["fieldmapper.IDL"]) {
                     pkey_sequence : fieldmapper._getAttributeNS(fields,this.NS_PERSIST, 'sequence')
                 };
 
-               var valid = fieldmapper._getAttributeNS(node,this.NS_OBJ, 'validate');
-               if (valid) obj.validate = new RegExp( valid );
+                var valid = fieldmapper._getAttributeNS(node,this.NS_OBJ, 'validate');
+                if (valid) obj.validate = new RegExp( valid.replace(/\\/g, '\\\\') );
 
                 var permacrud = node.getElementsByTagName('permacrud')[0];
                 if(permacrud) {