I'm tying to build a wizard on my website. Like every wizard, it has steps. For every step you can go either forward or backwards to previous step. I'm handling this navigation among steps with ajax. Every step is defined on a div. Each step has the same class, and a unique id which indicates the step. So, for navigating I defined the following js function, On which the parameter is the id of the step to show.
function navigateStepWizard(id) {
//hide all steps
$('.wizard-step').hide();
//show proper step
$(id).fadeIn("fast");
return false;
}
Now, the problem I'm facing is that on one of this steps I have several fields that must be validated before going to next step. I've defined validators (Faces Validator Clases) for each field on a form which are being executed when trying to go to next step, returning appropriate Ok/Error messages. My problem is that when this fields are not correct, the button does go to next step. First I've tried to use oncomplete
which always executed the js function, so I've changes to onsuccess
thinking that when a validation is not ok, the ajax callback wont execute the onsuccess
js function, but it does... here's my button code
<p:commandLink id="go-to-step-X"
actionListener="#{myBean.submitWizardInfo}"
onsuccess="navigateStepWizard('#wizard-step-X');"
process="@form, @([id$=wizzard])"
update="@form, @([id$=wizzard])">
Go to next step...
</p:commandLink>
Is there a way to do this avoiding the onsuccess
AJAX call when a field is not ok? Thanks for your time!
P.D: I'm using JSF 2.0 & PrimeFaces 5.0.