jsfbootsfaces

How to validate whether my form is valid from an oncomplete function in a b:commandButton?


I'm using bootsfaces 1.3.0 from maven repository and I'm trying to use this commandButton example that is in the docs (https://showcase.bootsfaces.net/forms/commandButton.jsf):

<b:commandButton 
    value="Ajax Modal" 
    ajax="true" 
    update="form:inform amodal" 
    look="inverse"
    oncomplete="if(validationFailed) alert('Please enter valid input before opening the modal'); else $('#amodal').modal('show')" />

It fails because it says validationFailed is not defined. Could somebody help me with showing me how to do this or showing me where it's explained in the docs?

I'm trying to build a functionality to change passwords on a b:modal validating the actual password and checking password validity of the new one.

I've tried using implicit object facesContext, and I've checked if the answer to primefaces (args.validationFailed) could also be used in bootsfaces.

This is my code:

<b:commandButton
    value="Change Password"
    action="#{user.changePassword()}"
    ajax="true"
    update="@Form"
    oncomplete="handleDialogSubmit(validationFailed)" />

Solution

  • The JavaScript variable validationFailed must be provided by BootsFaces. To accomplish this, you must use the <b:fetchBeanInfos /> component. It takes the server's information and makes it "visible" in the client side.

    See https://showcase.bootsfaces.net/forms/FetchBeanInfos.jsf