// This SSJS script library consolidates all the validation in one place // The postValidationError() function flags a control as invalid and provides an error message // so that the XPages ErrorMessage control is used to display the error on the page. var validateForm = function(){ var valid = true; var control; var val; // *** REPEAT THE FOLLOWING BLOCK OF CODE FOR EACH CONTROL FOR BASIC "REQUIRED" VALIDATION // For each field, change the Control Name in getComponent() and the error message text in postValidationError() // Optionally, modify the IF conditions with more complex JavaScript for value ranges, regular expressions, data lookups, etc. control = getComponent("title1"); val = control.getValue(); if (isEmpty(val)){ valid = false; postValidationError(control,"Please enter a Title"); } // *** ---------------------------------------------------------------- *** return valid; } function postValidationError(control, msg) { if ((typeof msg) != "string") return; var msgObj = new javax.faces.application.FacesMessage(javax.faces.application.FacesMessage.SEVERITY_ERROR, msg, msg); facesContext.addMessage(control.getClientId(facesContext), msgObj); control.setValid(false); } function isEmpty(o){ return (o == null || @Trim($A(o)[0]) == "" ) ? true : false; } function $A( object ){ try { if( typeof object === 'undefined' || object === null ){ return []; } if( typeof object === 'string' ){ return [ object ]; } if( typeof object.toArray !== 'undefined' ){return object.toArray();} if( object.constructor === Array ){ return object; } return [ object ]; } catch( e ) { Debug.exceptionToPage( e ); } }