function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JoshVHJoshVH 

CommandButton Question

I am using an apex:commandbutton to post some data to a Controller extension and rerender areas on the same page the commandbutton is on.  Also, I have some JavaScript that executes in the commandbutton's oncomplete attribute.  My question is how can I determine in my JavaScript if validation errors occurred when the button was clicked?  Basically I only want my oncomplete code to execute if there were no validation errors.  An example of a validation error in this case would be an inputfield marked as required that is not populated.

 

 

<apex:commandButton oncomplete="PrintContent();" action="{!Generate}" rerender="barcodes,pagemessages" value="Generate Coversheet"/>

 

 

stephanstephan

One thing you might try is in your PrintContent function, looking at the innerHTML of your pagemessages, and then conditionally proceeding if there isn't anything being displayed.

sforce2009sforce2009

You can set a boolean property in your extension class to true in your postData method. And check the value in Oncomplete method.

 

funciton yourOncompleteJs()

{

if('{!yourBoolValue}' == 'true')

{

//proceed

return true;

}

return false;

}

Hope this helps. I have not tested it though.

JoshVHJoshVH

sforce2009 wrote:

You can set a boolean property in your extension class to true in your postData method. And check the value in Oncomplete method.

 

funciton yourOncompleteJs()

{

if('{!yourBoolValue}' == 'true')

{

//proceed

return true;

}

return false;

}

Hope this helps. I have not tested it though.


 

Since there are validation errors it never gets to my "postData" method in my controller.  Therefore I am not able to set the boolean value and check it "OnComplete".

sforce2009sforce2009

If I understand you correctly,

You want to execute the onComplete only when there are no errors after postback.

What I sugested was you will take boolVlaue whose default value is false. and You will make it true inside your postback function.

 

So in oncomplete when you check if the value is true, the code will execute only if it is true otherwise you simply return false;

Hope I am pointing you to right direction. Otherwise if you could elobarate more with the code, it would be helpful to identify and provide a solution to your problem.

 

Thanks