You need to sign in to do that
Don't have an account?
JoshVH
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"/>
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.
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".
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