From a435003a478ba48089a7da467fee883b8bb8b69d Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 2 Jun 2010 15:11:52 +0000 Subject: [PATCH] add class/instance methods for checking required-ness and validity of an object field in JS FM implementation git-svn-id: svn://svn.open-ils.org/ILS/trunk@16557 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js | 21 ++++++++++++++++++++- Open-ILS/web/js/dojo/fieldmapper/IDL.js | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js b/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js index da16e20a2..4d4f9c34f 100644 --- a/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js +++ b/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js @@ -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; + } + /* diff --git a/Open-ILS/web/js/dojo/fieldmapper/IDL.js b/Open-ILS/web/js/dojo/fieldmapper/IDL.js index b0ee5ea3d..17fcdffb2 100644 --- a/Open-ILS/web/js/dojo/fieldmapper/IDL.js +++ b/Open-ILS/web/js/dojo/fieldmapper/IDL.js @@ -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) { -- 2.11.0