0

When try to click the tabs very fast two tabs got Selected in Jquery SmartWizard.js plug-in i tried this way but no luck any one experienced this... and also tried .on /.off events no luck.

$($this.steps).bind("click", function (e) {

    //e.stopImmediatePropagation();       
    $($this.steps).unbind("click");

    if ($this.steps.index(this) == $this.curStepIdx) {

        return false;
    }
    var nextStepIdx = $this.steps.index(this);
    var isDone = $this.steps.eq(nextStepIdx).attr("isDone") - 0;
    if (isDone == 1) {
        _loadContent($this, nextStepIdx);
    }

    $($this.steps).bind("click");
    return false;
});
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
Chandru velan
  • 136
  • 1
  • 3
  • 21
  • 2
    You should use `on` anyways. `bind` is outdated. – John Dvorak Aug 02 '13 at 06:36
  • i tried with .on/.off events but no luck in the question itself i mentioned it. – Chandru velan Aug 02 '13 at 07:40
  • As I mentioned in the chat, you should use `on` instead of `bind` even if it doesn't solve your immediate problem. – John Dvorak Aug 02 '13 at 07:41
  • 1
    Can you provide a jsfiddle? – Luke Aug 06 '13 at 21:10
  • @Luke i'm restricted to post code, its violating organization rules actually and i dont have time depict the same with b'cas i've made lot of changes in the plugin regarding with my requirement and i skipped to the next task, Actually its part of plugin code i 've given the plug-in site reference in below comments sorry for that, if i find time i'll try to post the code in fiddler. – Chandru velan Aug 07 '13 at 09:07

5 Answers5

0

Maybe set a global variable and check if the global variable is true? You could set a short delay with the built-in javascript delay() function for just a very small period of time after clicking. For example,

go=true;
onclick:
    go=false;
    delay(100, some filler event);
    go=true;

EDIT: this link might help: http://ejohn.org/blog/how-javascript-timers-work/

EDIT: try this in jQuery:

$('id').click(function() {return false;});

Then set a delay and set it back.

EDIT: this seems to work for me. Notice if you click the link twice with a small delay, it'll only flash once. Unless you spam the button about 10 times really quickly, it works fine. (Using latest Chrome btw)

EDIT: http://jsfiddle.net/ZDHZv/2/ works fine for me. If you use that method for tabs, then it's impossible to get double selects. Implement that with whatever plugin you're using with $('.selected')

  • Hm... Although I haven't tested the code, I don't think that makes any sense. If you require the variable to be true to execute the onclick event and it's not true, then it shouldn't run - unless of course, somehow the browser sends two events and runs them in different threads, in which case, I have no idea. –  Aug 05 '13 at 09:47
  • i have posted part of the plug in code here, where i need to customize as per my requirement for full code please follow the link https://github.com/mstratman/jQuery-Smart-Wizard/blob/master/js/jquery.smartWizard.js – Chandru velan Aug 05 '13 at 11:13
  • Sorry, since I don't want to deal with 400 lines of code I'm going to try to write my own code to simulate your problem. Just to be clear, you're getting two windows opening when you double click a link? –  Aug 06 '13 at 00:57
  • actually in my case it opening only one window but two tabs got selected at that time, it should be only one tab to got selected with corresponding screen – Chandru velan Aug 06 '13 at 09:46
  • Oh, well did you see my code? It should apply to any element. You can disable click listeners that way. I'll write some examples with tabs. –  Aug 07 '13 at 00:58
  • i cannot restrict user to wait one second like in your fiddler example and at times your code requires two clicks for the tab selection did you noticed that? – Chandru velan Aug 07 '13 at 09:01
  • Then change it to something like 100 rather than 1000. Also, the only reason why it needs 2 clicks is because the listener has been disabled. I thought you wanted to disable the listener, so that's what I did. –  Aug 07 '13 at 09:13
  • i've mentioned in the question itself "clicking very fast" since i'm allowing the user to click without any time delay, so i cannot use any timer events to set delay in the event firing, thats the tricky part man else i would have tried with delay events(like timers), i've to allow the user to click very fast and same time two tabs cannot be selected at a time. – Chandru velan Aug 07 '13 at 09:33
0

I usually do something like this:

var selection;
$('a').click(function () {
    if (selection !== undefined) {
        selection.removeClass('selected');
    }
    selection = $(this);
    selection.addClass('selected');
});

http://jsfiddle.net/ZDHZv/7/

But it occurred to me that you could also do this, assuming all the tabs were siblings and nothing else was:

$('a').click(function () {
    $(this).addClass('selected');
    $(this).siblings().removeClass('selected');
});

http://jsfiddle.net/ZDHZv/9/

Roy J
  • 42,522
  • 10
  • 78
  • 102
0

You can try something like this:

var process = false;
$($this.steps).bind("click", function (e) {
    if (process) {
        return false;
    }
    process = true; 

    if ($this.steps.index(this) == $this.curStepIdx) {

        return false;
    }
    var nextStepIdx = $this.steps.index(this);
    var isDone = $this.steps.eq(nextStepIdx).attr("isDone") - 0;
    if (isDone == 1) {
        _loadContent($this, nextStepIdx);
    }
    process = false;
    return false;
});
jcubic
  • 61,973
  • 54
  • 229
  • 402
  • it was my last try before posting the question here i tried this way but no luck, if i follow the above i can still able to select two tabs thanks for your reply.. – Chandru velan Aug 12 '13 at 05:18
0

After I readed your 400+ lines of source code, I think I know where the problem is.

It is in the function _loadContent. Content loading is asynchronous because of ajax, and you set selected after ajax loading.

So the next tab can be selected when the previous tab is loading although its click is finished.

I get two answers for you.

  1. Make the ajax synchronized.Like

    var ajax_args = {
        ...
        async : false,
        ...
    

    It can promise the order of selected and all. But, as you know, it will forced user waiting until content loading finished too.

  2. Set selected immediately, and set error style after.Like

    ...
    var stepNum = stepIdx + 1;
    _showStep($this, stepIdx);// add this to set selected immediately.
    if (ajaxurl && ajaxurl.length > 0) {
        if ($this.options.contentCache && hasContent) {
            return; // remove this and other _showStep calls.
        } else {
            var ajax_args = {
                ...
                error : function() {
                    $this.loader.hide();
                    $this.showError(stepIdx);// show error.
                },
                ...
    

    Order of selected will be ok. But ajax loading and error style will become asynchronous.

It is your call.

Clxy
  • 505
  • 1
  • 5
  • 13
  • i 've already made 'async:false' in my code, and i didn't use plugin default ajax call instead in loading with contents in External call before the plugin method call. thanks for your reply – Chandru velan Aug 12 '13 at 05:36
  • So... It was the reason and the problem solved? I am curious about the result. – Clxy Aug 12 '13 at 07:56
0

hi guy's thank you for your efforts i solved the issue by blocking the UI using UI block plugin

$($this.steps).on("click", function (e) {

    e.preventDefault();
    e.stopImmediatePropagation();
    if ($(this).attr('class') !== 'disabled' && $(this).attr('class') !== 'selected' && $(this).attr('class') !== 'error') {

        $('div.swMain').block({ message: "Processing..." });
    }

    try {

        if ($this.steps.index(this) == $this.curStepIdx) {

            $('div.swMain').unblock();
            return false;
        }

        var nextStepIdx = $this.steps.index(this);
        var isDone = $this.steps.eq(nextStepIdx).attr("isDone") - 0;
        if (isDone == 1) {           
            e.preventDefault();
            _loadContent($this, nextStepIdx);

        }
    }
    catch (e) {

        $($this.steps).on("click");
        console.log("Fast click Error ===>   " + e);
    }


    if ($(this).attr('class') !== 'disabled' && $(this).attr('class') !== 'selected' && $(this).attr('class') !== 'error') {

        $('div.swMain').unblock();
    }

    return false;
});
Chandru velan
  • 136
  • 1
  • 3
  • 21