Gerrit, You need to call .valid().form(), not just .valid(). Also, you
should probably use the form id "#contactForm8" instead of '.register'
jQuery selector. In other words, use Paul's code snippet:
button.add(new AttributeModifier("onclick", new Model<String>("if (!
$('#" + formMarkupId + "').validate().form()) {return false};"))On Wed, Feb 15, 2012 at 2:18 AM, Paul Jackson <[email protected]> wrote: > > This works for us: > > onclick="if (! $('#id45').validate().form()) {return false};if > (function(){return Wicket.$$(this)&&Wicket.$$('id45')}.bind(this)()) { > Wicket.showIncrementally('busyIndicator');}var > wcall=wicketSubmitFormById('id45', > '?x=cu02w6454cTq5HSn4Av8ZXGRwfcS*bDlrHDXn8GklQ6Sh3RC2Dgwz8XwqsEQE*Jo7KvmsA5Uh0NowPRWPoKW7z8clW5Md9oNtKs9d1v0BgjqKNKS-oluEmHYF0Tjrkqq8T76MXi*zlTAtfj5YLHG3gKsV2tb4R*z', > 'address:pafForm:pafSearch' ,function() { > ;Wicket.hideIncrementally('busyIndicator');}.bind(this),function() { > ;Wicket.hideIncrementally('busyIndicator');}.bind(this), function() {return > Wicket.$$(this)&&Wicket.$$('id45')}.bind(this));;; return false;" > > It's basically the same, with some extras bits for busy indicators and such. > > Paul > > -----Original Message----- > From: Gerrit Scholz | QUERPLEX.de [mailto:[email protected]] > Sent: 15 February 2012 09:09 > To: [email protected] > Subject: AW: jQuery form validation with wicket ajax > > I prepend "if(!$('.register').valid()) { return false;};" to the onclick > attribute. > This statement call the jQuery validator for the form. > > The onclick attribute without my changes (AjaxRequestTarget not null): > > onclick="var wcall=wicketSubmitFormById('contactForm8', > '../kemner/?wicket:interface=:4:contactForm:sendContact::IActivePageBehaviorListener:0:1&wicket:ignoreIfNotActive=true', > 'sendContact' ,function() { }.bind(this),function() { }.bind(this), > function() {return Wicket.$$(this)&&Wicket.$$('contactForm8')}.bind(this));;; > return false;" > > onclick with my changes (AjaxRequestTarget null): > > onclick=" if(!$('.register').valid()) { return false;}; var > wcall=wicketSubmitFormById('contactForm8', > '../kemner/?wicket:interface=:4:contactForm:sendContact::IActivePageBehaviorListener:0:1&wicket:ignoreIfNotActive=true', > 'sendContact' ,function() { }.bind(this),function() { }.bind(this), > function() {return Wicket.$$(this)&&Wicket.$$('contactForm8')}.bind(this));;; > return false;" > > Gerrit > > -----Ursprüngliche Nachricht----- > Von: Alec Swan [mailto:[email protected]] > Gesendet: Dienstag, 14. Februar 2012 18:50 > An: [email protected] > Betreff: Re: jQuery form validation with wicket ajax > > Are you saying that AjaxRequestTarget is not null without your onclick > attribute changes and is null with your changes? If so, please post the > changes you made to onclick attribute. > > On Tue, Feb 14, 2012 at 7:06 AM, Gerrit Scholz | QUERPLEX.de > <[email protected]> wrote: >> If I intercept the onclick event my function is called but the processing >> not stop. Mean that the wicket (onclick) javascript is running parallel. >> So I write a AttributeModifier that prepends my function to the onclick >> attribute. Now the validation works fine, but on the onSubmit method of the >> wicket ajax button the AjaxRequestTarget is null so the component to refresh >> cannot be added. >> >> Gerrit >> >> -----Ursprüngliche Nachricht----- >> Von: Paul Jackson [mailto:[email protected]] >> Gesendet: Dienstag, 14. Februar 2012 10:38 >> An: [email protected] >> Betreff: RE: jQuery form validation with wicket ajax >> >> Thanks for that link! I never managed to work out how to get jquery events >> to override the buttons onClick attribute. This should simplify our >> validation code a lot. >> >> Paul >> >> -----Original Message----- >> From: Alec Swan [mailto:[email protected]] >> Sent: 13 February 2012 16:38 >> To: [email protected] >> Subject: Re: jQuery form validation with wicket ajax >> >> This thread describes a purely client-side solution to your problem: >> http://stackoverflow.com/questions/1506729/how-to-intercept-the-onclick-event. >> You can solve this problem for all you AJAX links by assigning them a >> special class, e.g. class="ajaxLink", and then apply the technique to >> $("form .ajaxLink"). >> >> On Mon, Feb 13, 2012 at 3:55 AM, Paul Jackson <[email protected]> wrote: >>> We use an OnBeforeRenderListener to add onClick events to the buttons and >>> ajax buttons on a form that we want to be validated. We have to handle the >>> normal buttons and ajax buttons slightly differently. >>> >>> Ajax button: >>> >>> button.add(new AttributeModifier("onclick", new >>> Model<String>("if (! $('#" + formMarkupId >>> + "').validate().form()) {return false};")) { >>> >>> Normal Button: >>> >>> button.add(new WiQueryEventBehavior(new >>> Event(MouseEvent.CLICK) { >>> @Override >>> public JsScope callback() { >>> return JsScope.quickScope("return $('#" + >>> formMarkupId + "').validate().form();"); >>> } >>> })); >>> >>> Hope that helps. >>> >>> Paul >>> >>> -----Original Message----- >>> From: Gerrit Scholz | QUERPLEX.de [mailto:[email protected]] >>> Sent: 13 February 2012 10:18 >>> To: [email protected] >>> Subject: jQuery form validation with wicket ajax >>> >>> Hello there, >>> I try to use jQuery validaton (http://docs.jquery.com/Plugins/Validation) >>> with a wicket AJAX button. I register the jQuery validator on the form. If >>> I use a normal wicket submit button or link, the jQuery form validation >>> works. But if I use an AJAX button or link, the jQuery form validation is >>> not called. How can I call the jQuery validation before AJAX update. >>> Thanks, >>> Gerrit >>> >>> >>> >>> --------------------------------------------------------------------- >>> - >>> ----- QUERPLEX GmbH Nürnberg | www.querplex.de Kornmarkt 2 >>> D-90402 Nürnberg >>> --------------------------------------------------------------------- >>> - >>> ----- >>> Tel +49 (0)911 94 11 98 - 0 >>> Fax +49 (0)911 94 11 98 - 59 >>> --------------------------------------------------------------------- >>> - >>> ----- >>> Registergericht Nürnberg HRB 20 123 >>> Geschäftsführerin: Angelika Benkert >>> --------------------------------------------------------------------- >>> - >>> ----- >>> ********************************************************************* >>> * Please consider the environment - do you really need to print this >>> email? >>> >>> This email is intended only for the person(s) named above and may contain >>> private and confidential information. If it has come to you in error, >>> please destroy and permanently delete any copy in your possession and >>> contact us on +44 (0) 161 480 4420. The information in this email is >>> copyright © CDL Group Holdings Limited. We cannot accept any liability for >>> any loss or damage sustained as a result of software viruses. It is your >>> responsibility to carry out such virus checking as is necessary before >>> opening any attachment. >>> >>> Cheshire Datasystems Limited uses software which automatically screens >>> incoming emails for inappropriate content and attachments. If the software >>> identifies such content or attachment, the email will be forwarded to our >>> Technology Department for checking. You should be aware that any email >>> which you send to Cheshire Datasystems Limited is subject to this procedure. >>> >>> Cheshire Datasystems Limited, Strata House, Kings Reach Road, >>> Stockport SK4 2HD Registered in England and Wales with Company Number >>> 3991057 VAT registration: 727 1188 33 >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> >> >> ---------------------------------------------------------------------- >> ----- QUERPLEX GmbH Nürnberg | www.querplex.de Kornmarkt 2 >> D-90402 Nürnberg >> ---------------------------------------------------------------------- >> ----- >> Tel +49 (0)911 94 11 98 - 0 >> Fax +49 (0)911 94 11 98 - 59 >> ---------------------------------------------------------------------- >> ----- >> Registergericht Nürnberg HRB 20 123 >> Geschäftsführerin: Angelika Benkert >> ---------------------------------------------------------------------- >> ----- >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > > --------------------------------------------------------------------------- > QUERPLEX GmbH Nürnberg | www.querplex.de Kornmarkt 2 > D-90402 Nürnberg > --------------------------------------------------------------------------- > Tel +49 (0)911 94 11 98 - 0 > Fax +49 (0)911 94 11 98 - 59 > --------------------------------------------------------------------------- > Registergericht Nürnberg HRB 20 123 > Geschäftsführerin: Angelika Benkert > --------------------------------------------------------------------------- > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
