sathomas / acc-wizard

Wizard implementation for bootstrap based on accordion
216 stars 76 forks source link

beforeNext with return false does not work #23

Closed ubergeekzone closed 9 years ago

ubergeekzone commented 10 years ago

I have a beforeNext with a return false and it does not stop the execute it just goes to the next step, but the beforeNext is being fired because i can see my alert() i put in there for debugging. Any ideas?

function beforeNext() { if($('#name').val() == "") { return false;
}

$(".acc-wizard").accwizard({beforeNext: function (parent, panel) {
hash = "#" + panel.id; if(hash == "#information") { alert(beforeNext()); } }, onNext: onNext});

ubergeekzone commented 10 years ago

I fixed my own issue. Here is how

function beforeNext(e) { e.preventDefault();
}

do not use return false like the developer states in there documents, it will not work. use e.preventDefault() instead.

I hope this helps someone else out if they were having the same issue i was having.

cleguienne commented 10 years ago

Hi I went through the same problem , the false return value won't stop the accordion to go further. Though, I don't understand how you get the "e" parameter in your beforeNext function as the parameters should be "parent" and "panel" , not an single event.

ubergeekzone commented 10 years ago

Because we are calling it in a function outside of the plug-in. It works as it should i would think.

b3457m0d3 commented 10 years ago

I was very confused by this solution, but it does, in fact, work as atlantawebco describes. First, create a function outside the scope of the acc-wizard initialization call. For the sake of simplicity let's call this function 'onBeforeNext()', and it simply grabs the event in e and uses it to call the method preventDefault(): function onBeforeNext(e){ e.preventDefault(); } now in the initialization call, we pass the acc-wizard specific method beforeNext(parent,panel){} and wherever you would have placed return false; you instead call the onBeforeNext() function. I feel as though this should be explained in the README.

ubergeekzone commented 10 years ago

Glad to hear it helped you out.

kieranmaltz commented 9 years ago

Is there any reason we don't just want to fix this? I have an implementation in place that works effectively:

.click(function (a) { a.preventDefault(); var n = t(this).parents(".panel-collapse")[0]; if (p("beforeNext", n) === false) { return; } var s = "#" + t(".panel-collapse", t(n).parents(".panel").next(".panel")[0])[0].id; t(s).collapse("show"), p("onNext", n), d = s, i(d), e.location.hash = d })

Edit: Upon reviewing the code (I was planning on integrating my fix), it looks like the exact fix that I made is already in place! image

sathomas commented 9 years ago

Is there any reason we don't just want to fix this?

Unfortunately, I don't have the time at the moment.