0

I have a javascript validation on click of command button(onclick="return validationFunc();"). When the validation is failing the backend action is not getting called(which is expected),however the action does not get called when the validation is passing.

<apex:commandbutton onclick="return validationFunc();" action="{!backendAction}"/>

function validationFunc(){
//when validation fails
return false;
//when validation passes
return true;
}
1

This will not work together. Refer to this answer: Visualforce onclick doesn't execute action or rerender

You would have to create Action Function to achieve desired functionality.

<apex:actionFunction name="backendAction" action="{!backendAction}"/> 

<apex:commandButton onclick="validationFunc();"/>

JS

function validationFunc(){
//when validation pass
backendAction();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.