You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Marco Di Sabatino Di Diodoro <ma...@tirasa.net> on 2013/07/24 10:54:59 UTC
DropDownChoice with Confirm Dialog
Hi all,
I like implement a DropDownChoice with an Confirm Dialog.
I used an AjaxFormComponentUpdatingBehavior("on change") to intercept the change in the DropDownChoice.
In addition, the user must first confirm the operation with a dialog before changing the value in the DropDownChoice.
To do that I add an AjaxCallListeners:
@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
final AjaxCallListener ajaxCallListener = new AjaxCallListener() {
private static final long serialVersionUID = 7160235486520935153L;
@Override
public CharSequence getPrecondition(final Component component) {
return "if (confirm('" + getString("confirmDelete") + "')) return false;";
}
};
attributes.getAjaxCallListeners().add(ajaxCallListener);
}});
When I click cancel on the Confirm Dialog, the DropDownChoice changes and I can not restore the old value.
How I understand that the user clicked on Cancel? Is the correct way to implement this functionality?
Best Regards
M
--
Dott. Marco Di Sabatino Di Diodoro
Tel. +39 3939065570
Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 0859111173
http://www.tirasa.net
Apache Syncope PMC Member
http://people.apache.org/~mdisabatino/
Re: DropDownChoice with Confirm Dialog
Posted by Martin Grigorov <mg...@apache.org>.
This is purely JS problem.
I don't find anything in the web that can do this automatically for you.
Here is a possible solution:
store the previous selected value in a custom attribute, e.g.
data-prev-index=...
then in the precondition code replace attrs.event.preventDefault() with :
var $select = $('#'+attrs.c); $select[0].selectedIndex =
$select.data("prev-index");
On Wed, Jul 24, 2013 at 2:10 PM, Marco Di Sabatino Di Diodoro <
marco.disabatino@tirasa.net> wrote:
> Hi Martin,
>
> attrs.event.preventDefault() not work. My DropDownChoice changes always.
>
> M
>
> Il giorno 24/lug/2013, alle ore 10:59, Martin Grigorov <
> mgrigorov@apache.org> ha scritto:
>
> > Hi,
> >
> >
> > On Wed, Jul 24, 2013 at 11:54 AM, Marco Di Sabatino Di Diodoro <
> > marco.disabatino@tirasa.net> wrote:
> >
> >> Hi all,
> >>
> >> I like implement a DropDownChoice with an Confirm Dialog.
> >> I used an AjaxFormComponentUpdatingBehavior("on change") to intercept
> the
> >> change in the DropDownChoice.
> >> In addition, the user must first confirm the operation with a dialog
> >> before changing the value in the DropDownChoice.
> >>
> >> To do that I add an AjaxCallListeners:
> >>
> >> @Override
> >> protected void updateAjaxAttributes(final
> >> AjaxRequestAttributes attributes) {
> >> super.updateAjaxAttributes(attributes);
> >> final AjaxCallListener ajaxCallListener = new
> >> AjaxCallListener() {
> >> private static final long serialVersionUID =
> >> 7160235486520935153L;
> >>
> >> @Override
> >> public CharSequence getPrecondition(final Component
> >> component) {
> >> return "if (confirm('" +
> >> getString("confirmDelete") + "')) return false;";
> >>
> >
> > Try with: return "if (confirm('" +
> getString("confirmDelete") +
> > "')) { attrs.event.preventDefault(); return false;}";
> >
> > The precondition just stops the Ajax call, but it has no logic to do
> > anything else.
> >
> >
> >> }
> >> };
> >> attributes.getAjaxCallListeners().add(ajaxCallListener);
> >> }});
> >>
> >> When I click cancel on the Confirm Dialog, the DropDownChoice changes
> and
> >> I can not restore the old value.
> >> How I understand that the user clicked on Cancel? Is the correct way to
> >> implement this functionality?
> >>
> >> Best Regards
> >> M
> >>
> >> --
> >> Dott. Marco Di Sabatino Di Diodoro
> >> Tel. +39 3939065570
> >>
> >> Tirasa S.r.l.
> >> Viale D'Annunzio 267 - 65127 Pescara
> >> Tel +39 0859116307 / FAX +39 0859111173
> >> http://www.tirasa.net
> >>
> >> Apache Syncope PMC Member
> >> http://people.apache.org/~mdisabatino/
> >>
> >>
>
> --
> Dott. Marco Di Sabatino Di Diodoro
> Tel. +39 3939065570
>
> Tirasa S.r.l.
> Viale D'Annunzio 267 - 65127 Pescara
> Tel +39 0859116307 / FAX +39 0859111173
> http://www.tirasa.net
>
> Apache Syncope PMC Member
> http://people.apache.org/~mdisabatino/
>
>
Re: DropDownChoice with Confirm Dialog
Posted by Marco Di Sabatino Di Diodoro <ma...@tirasa.net>.
Hi Martin,
attrs.event.preventDefault() not work. My DropDownChoice changes always.
M
Il giorno 24/lug/2013, alle ore 10:59, Martin Grigorov <mg...@apache.org> ha scritto:
> Hi,
>
>
> On Wed, Jul 24, 2013 at 11:54 AM, Marco Di Sabatino Di Diodoro <
> marco.disabatino@tirasa.net> wrote:
>
>> Hi all,
>>
>> I like implement a DropDownChoice with an Confirm Dialog.
>> I used an AjaxFormComponentUpdatingBehavior("on change") to intercept the
>> change in the DropDownChoice.
>> In addition, the user must first confirm the operation with a dialog
>> before changing the value in the DropDownChoice.
>>
>> To do that I add an AjaxCallListeners:
>>
>> @Override
>> protected void updateAjaxAttributes(final
>> AjaxRequestAttributes attributes) {
>> super.updateAjaxAttributes(attributes);
>> final AjaxCallListener ajaxCallListener = new
>> AjaxCallListener() {
>> private static final long serialVersionUID =
>> 7160235486520935153L;
>>
>> @Override
>> public CharSequence getPrecondition(final Component
>> component) {
>> return "if (confirm('" +
>> getString("confirmDelete") + "')) return false;";
>>
>
> Try with: return "if (confirm('" + getString("confirmDelete") +
> "')) { attrs.event.preventDefault(); return false;}";
>
> The precondition just stops the Ajax call, but it has no logic to do
> anything else.
>
>
>> }
>> };
>> attributes.getAjaxCallListeners().add(ajaxCallListener);
>> }});
>>
>> When I click cancel on the Confirm Dialog, the DropDownChoice changes and
>> I can not restore the old value.
>> How I understand that the user clicked on Cancel? Is the correct way to
>> implement this functionality?
>>
>> Best Regards
>> M
>>
>> --
>> Dott. Marco Di Sabatino Di Diodoro
>> Tel. +39 3939065570
>>
>> Tirasa S.r.l.
>> Viale D'Annunzio 267 - 65127 Pescara
>> Tel +39 0859116307 / FAX +39 0859111173
>> http://www.tirasa.net
>>
>> Apache Syncope PMC Member
>> http://people.apache.org/~mdisabatino/
>>
>>
--
Dott. Marco Di Sabatino Di Diodoro
Tel. +39 3939065570
Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 0859111173
http://www.tirasa.net
Apache Syncope PMC Member
http://people.apache.org/~mdisabatino/
Re: DropDownChoice with Confirm Dialog
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
On Wed, Jul 24, 2013 at 11:54 AM, Marco Di Sabatino Di Diodoro <
marco.disabatino@tirasa.net> wrote:
> Hi all,
>
> I like implement a DropDownChoice with an Confirm Dialog.
> I used an AjaxFormComponentUpdatingBehavior("on change") to intercept the
> change in the DropDownChoice.
> In addition, the user must first confirm the operation with a dialog
> before changing the value in the DropDownChoice.
>
> To do that I add an AjaxCallListeners:
>
> @Override
> protected void updateAjaxAttributes(final
> AjaxRequestAttributes attributes) {
> super.updateAjaxAttributes(attributes);
> final AjaxCallListener ajaxCallListener = new
> AjaxCallListener() {
> private static final long serialVersionUID =
> 7160235486520935153L;
>
> @Override
> public CharSequence getPrecondition(final Component
> component) {
> return "if (confirm('" +
> getString("confirmDelete") + "')) return false;";
>
Try with: return "if (confirm('" + getString("confirmDelete") +
"')) { attrs.event.preventDefault(); return false;}";
The precondition just stops the Ajax call, but it has no logic to do
anything else.
> }
> };
> attributes.getAjaxCallListeners().add(ajaxCallListener);
> }});
>
> When I click cancel on the Confirm Dialog, the DropDownChoice changes and
> I can not restore the old value.
> How I understand that the user clicked on Cancel? Is the correct way to
> implement this functionality?
>
> Best Regards
> M
>
> --
> Dott. Marco Di Sabatino Di Diodoro
> Tel. +39 3939065570
>
> Tirasa S.r.l.
> Viale D'Annunzio 267 - 65127 Pescara
> Tel +39 0859116307 / FAX +39 0859111173
> http://www.tirasa.net
>
> Apache Syncope PMC Member
> http://people.apache.org/~mdisabatino/
>
>