Javascript onClick event does not work with data-modal - Asp.Net Core MVC

Asked

Viewed 135 times

0

I have a Datatable in my Index where the lines are loaded using Javascript. The Edit, Details, Delete and History buttons are created together. They all open in a modal window (the modal block is inside the Index)... In the html of each button there is a "data-modal" tag in which it will serve as reference for the onclick event that will cause that button to open in the Modal window.

"columns": [
            { "data": "id", "name": "Id", "autoWidth": true },
            { "data": "descricao", "name": "Descricao", "autoWidth": true },
            { "data": "pessoaTipoDescricao", "name": "PessoaTipo", "autoWidth": true },
            {
              
                "render": function (data, type, full, meta) {
                    return '<a btnEditar title="Editar" data-modal="" href="/situacoes-gerenciamento/editar-situacao/' + full.id + '" class="btn btn-sm btn-icon btn-pure btn-default on-default edit-row"><span class="icon-2x wb-edit"></span></a> |' +
                           '<a title="Detalhes" data-modal="" href="/situacoes-gerenciamento/situacao-detalhes/' + full.id + '" class="btn btn-sm btn-icon btn-pure btn-default on-default footable-row-detail-row"><span class="icon-2x wb-search"></span></a> |' +
                           '<a title="Excluir" asp-action="Delete" data-modal="" class="btn btn-sm btn-icon btn-pure btn-default on-default remove-row"><span class="icon-2x wb-trash"></span></a> |' +
                           '<a title="Histórico" class="btn btn-sm btn-icon btn-pure btn-default on-default clockpicker" data-toggle="modal" data-target="#pessoaHistory" data-original-title="Histórico"><span class="icon-2x wb-time"></span></a>'
                }
            }
        ],

Problem: When clicking the "Edit" button the "data-model" tag seems not to be recognized and the onclick event is not working:

 $('a[data-modal]').on('click', function (e) {
        // Abre a janela modal com o formulário solicitado 
        openmodal(this.href);
        return false;
    });

Someone knows how to fix this?

  • But the attribute data-modal has no value. It was supposed to be worthless ?

  • The data-modal is worthless anyway. It is that when I loaded the datatable without using Javascript, the data-modal receives empty string. It is that I already have a block in my Index that builds the modal window. The data-modal attribute is only for me to call in the onclick event...

  • Interesting is that the New Sign Up button is not built using JS and works normally. The EDIT button , which was built via JS does not work... It seems that the data-modal does not work... <a id="btnNovo" Asp-action="Create" data-modal="" class="btn btn-Outline btn-default new" data-toggle="tooltip" data-original-title="Register New" data-container="body"> <span title="Register New" class="icon Wb-plus"></span> Register New </a>

1 answer

0

We’re missing a ] in the $('a[data-modal')

  • That carelessness... I posted with an error... But Currently has the key closed... I will correct the post. The Problem continues...

Browser other questions tagged

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