Javascript - Remove the event by clicking a button

Asked

Viewed 288 times

1

Good staff,

I have the following problem: as the following image shows, I have a set of buttons to move forward and backward the process sequence.

inserir a descrição da imagem aqui

However, exactly in this part, I need you to click on botão next the page waiting x segundos before proceeding. I have the following code to stop the propagation of the button click event and to move it forward again:

$('#btnnexttop, #btnnextdown').on('click', function (event) {
//só funciona quando o tab4 estver active 
var tab4 = $('#tab4').attr('class');
var svgShow = $('#capaemboss_laser').attr('class');
var embossChosen = $('#dlemboss2_laser').val();
//Imagens SVG criar com o btnnext em vez do preview 

if (svgShow == "row" && tab4 == "tab-pane active" && embossChosen != 'EMBOSS-D005') {

    var btnclicked = $(this).attr('id');
    //console.log(" teste" + btnclicked);
    event.stopPropagation();

    //obter o valor mais baixo do tamanho selecionado 
    var sizeVal = $("#dlformat2").val();
    var withouI = sizeVal.replace(/\i/g, '');
    var splitInt = withouI.split("x");
    var minValue = Math.min.apply(Math, splitInt);
    var pxValue = (minValue / 2) * 37.795276; // 37.795276 pixeis correspondem a 1cm! verificar!!


    //novo texto para as imagens
    var newText = $('#txt_emboss_laser').val();
    var newText2 = $('#txt_emboss2_laser').val();
    var newText3 = $('#txt_emboss3_laser').val();
    var newText4 = $('#txt_emboss4_laser').val();

    var svg_blob = "";

    //obter id da imagem selecionada 
    var imgSelected = $('#dlemboss2_laser').val();
    // por height igual ao pxValue

    setTimeout(function () {

        if (btnclicked == "btnnexttop") {
            $('#btnnexttop').off('click').trigger('click');
        } else if (btnclicked == "btnnextdown") {
            $('#btnnextdown').off('click').trigger('click');

        }
    }, 1000);
}});

My idea was to use the event.stopPropagation(); to stop the event by clicking the button and the setTimeout to do the trigger of a new click.

Problem: First click on each button next (represented with the ids: btnnextdown e btnnexttop) works perfectly, however, if I go back and make new click fails to work.

  • If you are interested and can refactor your code, I suggest you search "finite state machines" to solve this type of problem. A quick search to find a ready-made that works with jQuery.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.