Note that I can indeed console.log(getId('form_list_users'));.
That .reset() simply does nothing. No errors in console.Code:getId('form_list_users').reset(); // Stopped working. /* This works. */ //jQuery("input[type='checkbox']:checked").each(function() { // $(this).prop('checked', false); //});
And just in case, here's the complete code (I also have some other functions
in another file, like getId() and addClass()).
Code:/* === MARCAR TODOS OS CHECKBOXES DE UMA ÚNICA VEZ === {{{ */ jQuery('#check_all').click(function() { if (jQuery(this).prop('checked') == true) { jQuery("#table_list input[type='checkbox']").attr('checked', true); } else { jQuery("#table_list input[type='checkbox']").attr('checked', false); } }); /* Fim marcar checkboxes }}} */ /* ========== MENU DE AÇÕES DO USUÁRIO ====================== {{{ */ jQuery('.user_action').click(function() { /* Note o [] em id_arr[]. Sem eles não funciona. No html é um array mesmo. */ var num_checked_elems = $("#table_list input[name='id_arr[]']:checked").length; /* Salva um array com os checkboxes marcados. Será usado com as ações * 'publish' e 'unpublish' com ajax. */ var id_arr = []; $("#table_list input[name='id_arr[]']:checked").each(function() { id_arr.push(this.value); }); var allGood = true; /* O id nos indica qual ação o usuário está realizando. */ var action = $(this).attr('id'); //console.log(action); //return false; /* Colocamos o value do input hidden com a ação de acordo com o botão * que o usuário clickar no menu de ações. */ $('#form_list_users input[name=action]').attr('value', action); if (action == 'delete') { if (num_checked_elems < 1) { var txt = 'Selecione pelo menos um usuário.'; allGood = false; } /* TODO: Tirar esse 'confirm()' e levar o user para uma página bonitinha, * com os dados do usuário que ele quer deletar, ou com uma lista dos * usuários, de forma mais resumida, e aí ele confirma se sim ou não. */ else if (!window.confirm('Deseja realmente deletar este(s) usuário(s)?')) { allGood = false; var txt = 'A ação foi cancelada. Nehum usuário foi excluído.'; } } else if (action == 'edit') { if (num_checked_elems < 1) { var txt = 'Selecione um usuário.'; allGood = false; } else if (num_checked_elems > 1) { var txt = 'Não é possível editar mais que um usuário por vêz. Selecione apenas um.'; allGood = false; } } // Fim else if. else if (action == 'publish' || action == 'unpublish') { if (num_checked_elems < 1) { var txt = 'Selecione pelo menos um usuário para publicar ou despublicar.'; allGood = false; } } if (allGood == false) { var msgDiv = createMsgDiv(txt); /* Se já tem uma div, temos que removê-la para poder adicionar novamente, * já que a mensagem pode mudar, e portanto não basta apenas ver "se já * tem uma, não faz nada". */ if (hasClass(NSE(getId('action_buttons')), 'notice_msg')) { getId('action_buttons').parentNode.removeChild(NSE(getId('action_buttons'))); } /* Remove alguma div de mensagem possívelmente colocada com php. */ var success_msg = getClass('success_msg')[0]; if (success_msg) { success_msg.parentNode.removeChild(success_msg); } /* E colocamos a nova mensagem. */ if (!hasClass(NSE(getId('action_buttons')), 'notice_msg')) { getId('action_buttons').parentNode.insertBefore(msgDiv, NSE(getId('action_buttons'))); /* NOTA: Não vamos transformar isso em uma função pois as vêzes poderemos * ter que inserir as mensagens em outros lugares. */ } /* Desmarcamos os checkboxes. */ //getId('form_list_users').reset(); // Stopped working. jQuery("input[type='checkbox']:checked").each(function() { $(this).prop('checked', false); }); } else { // Submete o formulário com os checkboxes... if (action != 'publish' && action != 'unpublish') { $('#form_list_users').submit(); } else { // Vamos fazer por ajax. jQuery.post( 'index.php', {'action': action, 'id_arr': id_arr} ); jQuery(document).ajaxStop(function() { window.location.reload(); }); } } }); // Fim $('.user_action').click... /* Fim menu ações usuário. }}} */ /* ===== DATATABLE ============================================ {{{ */ /* Chamar o dataTable deve ser a última coisa a ser feita, * senão dá problemas. */ $('#table_list').dataTable({ 'aoColumnDefs': [ { 'bSortable': false, 'aTargets': [0] } ], 'bAutoWidth': false }); /* ==== dataTable fim. ==== }}}} */ /* vim:set foldmethod=marker foldmarker={{{,}}}: */


Reply With Quote

Bookmarks