atk4 / ui

Robust and easy to use PHP Framework for Web Apps
https://atk4-ui.readthedocs.io
MIT License
440 stars 105 forks source link

Lister with JS paginator can register events more than once #1932

Closed mvorisek closed 1 year ago

mvorisek commented 1 year ago

code to reproduce:

$crud = Crud::addTo($app);
$crud->setModel(new Country($app->db));
$crud->addJsPaginatorInContainer(20, 500 /* $containerHeight */);

steps to reproduce:

  1. open the repro code and scroll the CRUD to be on a newly loaded (via JS paginator) row
  2. click "edit" icon/action
  3. notice Uncaught Error: Unexpected modal to show - modal is already active console error

this is because row events registered by table selector are added by the JS paginator AJAX again:

$('#atk_layout_crud_view_table').on('click', '.b_atk_layout_crud_view_table_table_column_actionbuttons_button_1', function (event) {
    event.preventDefault();
    event.stopPropagation();
    $('#atk_layout_crud_useraction_modalexecutor').modal('show');
    $('#atk_layout_crud_useraction_modalexecutor').data('closeOnLoadingError', true);
    $('#atk_layout_crud_useraction_modalexecutor_loader').atkReloadView({'url': 'repro.php?__atk_cb_atk_layout_crud_useraction_modalexecutor_loader_callback=callback&__atk_cbtarget=atk_layout_crud_useraction_modalexecutor_loader_callback', 'urlOptions': {'atk_layout_crud_useraction_modalexecutor': $(this).closest('tr').data('id'), 'step': 'fields'}, 'apiConfig': {'method': 'post', 'onSuccess': function () {
    $('#atk_layout_crud_useraction_modalexecutor').removeData('closeOnLoadingError');
}}, 'storeName': null});
});