[ 8 posts ]

Jong-won Choi

  • Username: pbp
  • Joined: Tue Feb 15, 2011 7:52 pm
  • Posts: 5
  • Offline
  • Profile
Tags:

Confirmation before closing an accordion item

Post Posted: Tue Feb 15, 2011 8:31 pm
+0-
Hi

When a user clicks the close button, I want to ask a confirmation and stop or resume the closing procedure based on the input. I've tried:

accordion.on("beforeItemRemove", function (e) {
var answer = confirm("Really destroy?");
if (!answer) {
e.target.preventDefault(); }
});

Without a luck. Any hint?

Thanks!

pbp

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: Confirmation before closing an accordion item

Post Posted: Wed Feb 16, 2011 4:37 am
+0-
Hello Jong-won Choi.

I tried your snippet in the following example:
http://ipeychev.github.com/yui3-gallery ... items.html

I added those lines after accordion.render().

It seems it works correctly: the event is triggered, if the answer is ok, the items are removed, otherwise the actino is deleted.

Regards,
IceBox

Iliyan Peychev

YUI Contributor

  • Username: peychevi
  • Joined: Tue Feb 24, 2009 12:38 pm
  • Posts: 136
  • Location: Varna, Bulgaria
  • Twitter: ipeychev
  • GitHub: ipeychev
  • Gists: ipeychev
  • Offline
  • Profile
Tags:

Re: Confirmation before closing an accordion item

Post Posted: Wed Feb 16, 2011 2:07 pm
+0-
icebox wrote:
Hello Jong-won Choi.

I tried your snippet in the following example:
http://ipeychev.github.com/yui3-gallery ... items.html

I added those lines after accordion.render().

It seems it works correctly: the event is triggered, if the answer is ok, the items are removed, otherwise the actino is deleted.

Regards,
IceBox


That is actually incorrect.

This code:
e.target.preventDefault();

throws exception, because e.target does not have preventDefault function.
That's why the execution stops.


Jong-won Choi, there is no way to prevent that in the current version.
I just added that feature and you will see it with the next CDN push.

Iliyan

Jong-won Choi

  • Username: pbp
  • Joined: Tue Feb 15, 2011 7:52 pm
  • Posts: 5
  • Offline
  • Profile

Re: Confirmation before closing an accordion item

Post Posted: Wed Feb 16, 2011 2:07 pm
+0-
Hi Alberto

Uh, I guess 'e.target.preventDefault is not a function' error might be raised.

* * *

All,

Frankly. I do not know how to this properly. e.preventDefault() seems no effect.

Should I implement such code myself? I thought preventDefault() is exactly for that (I may be wrong though, I've started playing with YUI just a few weeks ago and I saw preventDefault function from one of videos which I do not remember anymore)

Any idea or pointer to look will be helpful

Thanks!

pbp

Jong-won Choi

  • Username: pbp
  • Joined: Tue Feb 15, 2011 7:52 pm
  • Posts: 5
  • Offline
  • Profile

Re: Confirmation before closing an accordion item

Post Posted: Wed Feb 16, 2011 2:11 pm
+0-
Iliyan,

I posted another message after reading Alberto's (and missed yours)

Thanks for the help

Cheers

pbp

Iliyan Peychev

YUI Contributor

  • Username: peychevi
  • Joined: Tue Feb 24, 2009 12:38 pm
  • Posts: 136
  • Location: Varna, Bulgaria
  • Twitter: ipeychev
  • GitHub: ipeychev
  • Gists: ipeychev
  • Offline
  • Profile

Re: Confirmation before closing an accordion item

Post Posted: Mon Feb 21, 2011 7:46 am
+0-
That change has been pushed to CDN already ('gallery-2011.02.18-23-10').

Iliyan

pasx

  • Joined: Wed May 18, 2011 2:55 pm
  • Posts: 8
  • Offline
  • Profile
Tags:

Re: Confirmation before closing an accordion item

Post Posted: Mon Nov 21, 2011 10:28 pm
+0-
Hi,
I am a bit confused. The forum mentions a correction but still it is unclear how one should implement this.
I am trying to do exactly the same thing:
Code:
        var answer = confirm("Delete?");
        if (!answer)
           event.halt();
        return answer;

I expected that returning false would be enough to stop the removal operation and failing that I tried event.preventDefault() which didn't work either.
In the end event.halt() does it for me.
Is it the recommended way?
Also is there a way to know what triggered the event in the first place? I am removing items by code which triggers this event and in this case I don't want to see the message of course. There are easy workarounds like storing a boolean somewhere but I was wondering if there is a nicer way to do it.
Thank you anyway so far I am doing great stuff with your accordion.

Iliyan Peychev

YUI Contributor

  • Username: peychevi
  • Joined: Tue Feb 24, 2009 12:38 pm
  • Posts: 136
  • Location: Varna, Bulgaria
  • Twitter: ipeychev
  • GitHub: ipeychev
  • Gists: ipeychev
  • Offline
  • Profile

Re: Confirmation before closing an accordion item

Post Posted: Tue Nov 22, 2011 1:35 pm
+0-
Hello,

pasx wrote:
Hi,
I am a bit confused. The forum mentions a correction but still it is unclear how one should implement this.
I am trying to do exactly the same thing:
Code:
        var answer = confirm("Delete?");
        if (!answer)
           event.halt();
        return answer;

I expected that returning false would be enough to stop the removal operation and failing that I tried event.preventDefault() which didn't work either.
In the end event.halt() does it for me.
Is it the recommended way?


The recommended way is shown in the first message of this thread:
Code:
accordion.on("beforeItemRemove", function (e) {
    accordion.on("beforeItemRemove", function (e) {
    var answer = confirm("Really destroy?");

    if (!answer) {
        e.target.preventDefault();
    }
    });


pasx wrote:
Also is there a way to know what triggered the event in the first place? I am removing items by code which triggers this event and in this case I don't want to see the message of course. There are easy workarounds like storing a boolean somewhere but I was wondering if there is a nicer way to do it.
Thank you anyway so far I am doing great stuff with your accordion.


In general, there is, but it is not applicable in our case. We usually add a parameter to the event which is called "src". As value, we set UI_SRC. In the listener, we check for that value.
However, in your case the best way probably would be just to remove the listener for this event before to close the item.

Iliyan
  [ 8 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum