Restrict SS/Server Side Validation to Only Fire when Button Clicked (and NOT Partial Refresh)

Mindwatering Incorporated

Author: Tripp W Black

Created: 12/11/2011 at 01:01 PM

 

Category:
Notes Developer Tips
XPages

Issue:
You have a Tabbed Panel or a partial refresh to compute some computedFields. Only problem is the fields that have validation inside that section fire their validation. How do you turn this off except for the buttons? (e.g. save/submit, and approve buttons)

Solution:
For the fields w/validation, go to the All Properties (side tab under Properties tab) --> basics --> required. It will be set to true. Change it something like the following:
return ( submittedBy( 'wp_BtnAppr' ) || submittedBy( 'wp_BtnSave' ) );

Uses function below (created by a developer named Tommy). Add the function to a Server-side JavaScript (SSJS) library. Then add the library to the XPage as a resource.

// Used to check which if a component triggered an update
function submittedBy( componentId ){
try {
var eventHandlerClientId = param.get( '$$xspsubmitid' );
var eventHandlerId = @RightBack( eventHandlerClientId, ':' );
var eventHandler = getComponent( eventHandlerId );
if( !eventHandler ){ return false; }

var parentComponent = eventHandler.getParent();
if( !parentComponent ){ return false; }

return ( parentComponent.getId() === componentId );
} catch( e ){ /*Debug.logException( e );*/ }
}



previous page