Does not work when pressing certain sequence of buttons, with js and html

Asked

Viewed 147 times

0

Good morning, stack overflow. I’m going through a strange problem, I don’t even know how to describe it.

Basically I have the 2 screens below inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

I am creating a form, where it will be necessary to register and edit in it. So my idea was to create 3 buttons, one to edit, or to register and another to cancel.

<div class="col-md-12">
        <a href="javascript:;" id="EdicaoLocalidade" class="btn green EditarLocalidade">Editar Localidade</a>
        <a href="javascript:;" id="CadastrarLocalidade" class="btn green CadastrarLocalidade">Cadastrar Localidade</a>
        <a href="javascript:;" class="btn default Cancelar">Cancelar</a>                            </div>

The idea is, when you press the New Locale button, you can make the Edit button disappear, leaving only the Sign Up and Cancel button.

inserir a descrição da imagem aqui

$('.page-toolbar a').click(function() {
            inicNovaLocalidade();
            $('.portlet.NovaLocalidade').slideDown();
            $(this).addClass('disabled');
            $(".EditarLocalidade").css("display","none");

        });

The same idea would be to edit it, when you click on the pen, next to the data, ie to edit.

inserir a descrição da imagem aqui

$(".Editar").on('click', function () {
            $('.portlet.NovaLocalidade').slideDown();
            $(".CadastrarLocalidade").css("display","none");

        })

The bizarre problem, is when I press Edit first, the cancel button does not work at all, but if I press the New Locale, cancel it, works right, for both cases.

My idea is that when I hit the cancel, besides giving the slide down, I would undo the hidden effect of the button.

//evento click do cancelar
$('#CadastroLocalidade a.Cancelar').click(function() {
    //teste para o botão cadastrar localidade
    var editLocalidade = document.getElementById("EdicaoLocalidade");
    var cadLocalidade = document.getElementById("CadastrarLocalidade");

    if(editLocalidade.style.display != 'none'){
        $('.portlet.NovaLocalidade').slideUp();
        $('.page-toolbar a').removeClass('disabled');
        $(".EditarLocalidade").css("display","inline-block");
    }


});

UPDATING

When I click on this button here, that the cancel does not work... in any way, this error

inserir a descrição da imagem aqui

  • What do you want to do is this? https://jsfiddle.net/mapquintal/fwx9qw1y/

  • No, I need that when I click on that edit arrow, work cancel for example... and I don’t understand why it doesn’t work

  • 1

    is calling $(". Edit"). on('click', Function() { instead of $(". Editarlocality"). on('click', Function () {

  • But that’s right, only cancel that doesn’t work, when I click on the Edit button

  • I can’t understand the mistake

  • I edited the question

Show 1 more comment

2 answers

0

In this Function, when clicking on register a hide on the edit button and vice versa. Clicking cancel again displays all buttons.

$("#operacao").on('click','a', function () {
    if($(this).attr("id") == "editar"){
        $("#cadastrar").hide();
        $("#editar").show();
    }else if($(this).attr("id") == "cadastrar"){
    	$("#cadastrar").show();
        $("#editar").hide();
    }else{
    	$("#cadastrar").show();
        $("#editar").show();
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="operacao">
    <a href="#?" id="editar">Editar</a>
    </br>
    <a href="#?" id="cadastrar">Cadastrar</a>
    </br>
    <a href="#?" id="cancelar">Cancelar</a> 
</div>

0

$('#CadastroLocalidade a.Cancelar').click(function() {

Element ID is wrong #Registration should be #CadastrarLocality

  • With the registration works, what I do not understand

  • @Gabrielfalieri pq 'Cadastrality' does not exist as an element id.

  • Name is wrong, change Register to Register'

  • what?? You understand what is happening?

  • Yes @Gabrielfalieri, I understand, you said the cancel button does not work.... Just because the jQuery button call is calling a button that doesn’t exist, the element ID is wrong, so the button doesn’t run.

  • If the code you have there in the development is the same that you posted here, I believe that is the problem. Try to change and test. = D

  • Look, when I click the New Locale, the same cancel works, it uses the same reference. When I use that little button, which I mentioned above, it doesn’t work... and theoretically it was supposed to work, because it makes the call to the same place

  • It’s just different buttons, but the cancel call is the same, when pressing in new location works first... cancel works in both cases, only when I click edit first

  • So man... you get what’s going on?

  • 1
Show 5 more comments

Browser other questions tagged

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