TheCoder4eu / BootsFaces-OSP

BootsFaces - Open Source Project
Apache License 2.0
246 stars 102 forks source link

how to check if form is valid in commandButton oncomplete #95

Closed bilak closed 9 years ago

bilak commented 9 years ago

Hi, as mentioned here is there any option how to check if validation was successful in onsubmit of commandButton? I have modal, after submit I'm navigated to next modal. When I return back to first modal, I can see validation messages and now I'm not able to move to next modal.

this is my button <b:commandButton ajax="true" value="#{label['button.next']}" type="submit" actionListener="#{registerUserMB.register}" look="primary" styleClass="pull-right" update="registerUserForm" oncomplete="hideModalAndShowAnother('registerUserModalPseudoClass','testModalPseudoClass');"/>

stephanrauh commented 9 years ago

If args.validationFailed is a standard JSF api parameter, it should be simple to access it using the b:commandButton (possibly it's only shadowed by our current implementation). However, every reference I found to args.validationFailed is about PrimeFaces, so I wonder if it's a PrimeFaces feature which is not available in standard JSF.

bilak commented 9 years ago

I think it's the PF feature https://code.google.com/p/primefaces/issues/detail?id=714

stephanrauh commented 9 years ago

I've implemented a component that allows you to bring server side info to the Javascript window scope. Currently, it only sets the global variable validationFailed. Note that this is a prototype - names and implementation details are still subject to change. A live demo of the prototype is available at http://www.bootsfaces.net/BootsFacesWeb/forms/commandButton.jsf.

stephanrauh commented 9 years ago

I've added a page to document this component.

Nick2324 commented 5 years ago

Hi,

I know this is a closed issue, but 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?

This is my code:

<b:commandButton 
                        value="Change Password"
                        action="#{user.changePassword()}"
                        ajax="true"
                        update="@form"
                        oncomplete="handleDialogSubmit(validationFailed)" />
stephanrauh commented 5 years ago

I guess you're Nick2324 from StackOverflow? Just for the record, if someone else stumbles over this question: the solution is to add a <b:fetchBeanInfos /> to the form. This widget adds the variable validationFailed (and several others) to the JavaScript namespace of the JSF page and updates it on every AJAX request.