You can set the Request Approval UI Action to run on the client (Client checkbox), set the Onclick field to requestApproval(); and then use the following code as a guideline for your script body. This allows your UI Action to run in two stages. On the client, where you can write your validation logic, and on the server (triggered by the gsftSubmit) when your validation logic has succeeded.
There are a few UI Actions in the system by default that employ this kind of code. Search for UI Actions where "Script contains gsftSubmit" to see other examples.
function requestApproval(){
// Do your client side validation here
if (g_form.getValue('comments') == '') {
return false; //Abort submission if your validation fails
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'request_approval');
// MUST call the 'Action name' set in this UI Action.
// Make sure this name doesn't conflict with an existing
// UI Action if this is a custom action.
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();
function serverResolve(){
change_request.state = 1;
// other server side actions you wish to take
}