wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marios Skounakis <msc...@gmail.com>
Subject Re: Javascript confirm with condition before submit
Date Fri, 21 Jun 2013 21:46:45 GMT
I personally like server side confirmations because they can be customized
based on the submitted data and you can use the model to customize the
confirmation. If you do it client side you need to do it in javascript and
using the component's values which is in my opinion ugly.

Usually I override onSubmit (either on the form or the ajax button) and
return the confirmation there. If the user confirms, I follow up with
another ajax call which actually commits the data.

This method has the following issues which you must take into consideration:
1. Because the confirmation is shown onSubmit, all validations happen
before the confirmation. If a component is invalid, processing stops before
the confirmation is shown. Also the form model has been updated. This may
or may not be a problem. If you are in a regular database app, this is okay
as long as your don't actually update the database.
2. Triggering a second ajax call after the user confirms is a bit tricky.
You need to add an AbstractDefaultAjaxBehavior to the page and call it's
getCallbackScript() if the user confirms. Then do the actual commit (e.g.
store to the db) in it's respond() method.
3. Also this approach requires an extra ajax call to actually commit the
form.

I sometimes do confirmations using wicket's ModalWindow (or my own
alternative JQuery-based implementation). This allows me to have a
consistent presentation for all modal dialogs, be it confirmation,
information or input dialogs. Also, using a ModalWindow allows for easier
implementation of issue (2) above as instead of using an
AbstractDefaultAjaxBehavior you can use the ModalWindow's CloseCallback to
do the actual commit.

There are other ways to do (2) above, such as having an extra ajax
button/link that you trigger by javascript if the user confirms and use
it's onSubmit method to actually commit the form.

The above is a rather condensed version of what you need to do, let me know
if you are interested and I can provide more details.


On Sat, Jun 22, 2013 at 12:06 AM, grignette <lady-elixir@hotmail.fr> wrote:

> Thanks for your answer.
>
> I'am sorry but I don't like the first solution. The second is better I
> think
> but I have 6 or 7 rules to implement like that. So it can be difficult.
>
> Someone have an other idea ? If no, I will try to implement the second
> solution...
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Javascript-confirm-with-condition-before-submit-tp4659672p4659682.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message