The problem and some confusion of yours (and mine, because I had to study jQuery UI and Bootstrap to answer) is that both Bootstrap and jQuery UI have dialogs/modals. So in his code he was loading Bootstrap but using Javascript/jQuery code for a jQueryUI dialog.
My answer assumes that you continue to use Bootstrap, and removes part of the code you had that was for jQuery UI.
So you need to change:
#1 - join the modal/dialog HTML somewhere on the page, for example:
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
Tem a certeza?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
<button type="button" class="btn btn-primary">Apagar</button>
</div>
</div>
</div>
</div>
#2 - change the HTML of the buttons to have Bootstrap attributes:
data-toggle="modal" data-target="#myModal"
#3 - change Javascript to use the Bootstrap library way
$('#myModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // botão que abriu o modal
var aRemover = button.closest('tr');
$('#confirmar').on('click', function () {
$('#myModal').modal('hide')
aRemover.fadeOut(500, function () {
aRemover.remove();
});
// aqui pode chamar o seu AJAX
});
});
$('#myModal').on('hide.bs.modal', function (event) {
$('#confirmar').off('click');
});
Note that in this case/example I used the suggested HTML in the Bootstrap documentation, and gave an ID to the delete button to be more convenient. The HTML I added is:
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">Tem a certeza?</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
<button type="button" id="confirmar" class="btn btn-primary">Confirmar</button>
</div>
</div>
</div>
</div>
P.S.: I saw now that you edited the question to use lists instead of table. Then you need to change:
var aRemover = button.closest('tr');
for
var aRemover = button.closest('li');
Is jsFiddle’s HTML the same as the original code? Check it out here: http://jsfiddle.net/a66fx2L5/
– Sergio
Hi Sergio, it’s actually almost that. But in mine is a list. I created altered the file to look similar as I am using in the project. Each item in the list has an automatically generated ID, I just want that when the user click "Remove" an AJAX call is made and with the success of it the line is removed. Is it possible to do it with the list? Here is the link: http://jsfiddle.net/joaoManolo/a66fx2L5/1/
– João Manolo
João this HTML is very different from the question... I think it was worth changing the question. However, this new HTML lacks the div #dialog. Take a look here: http://jsfiddle.net/a66fx2L5/5/ - if that’s what you want I can put an answer explaining better what was missing.
– Sergio
@Sergio, I agree with you. Well, the "disappear" part of the component works normally, as does the opening of the
dialog()
, but when I pass to my system the same does not work, that is, the dialog does not open and triggers an error on the console. I edited the question with the stack of errors for easy viewing.– João Manolo
Because in jsFiddle I added jQueryUI,
.js
and.css
, that’s what made the dialog work. I’ll see if I can find the Boostrap modal and put it here...– Sergio
So @Sergio, I use jQuery. I found the Bootstrap dialog (
BootstrapDialog.show({});
), but the same does not work. He accusesBootstrapDialog is not defined
.– João Manolo
Well, I’m preparing an answer, but I’m not finished today. I’ll do it tomorrow. It either makes jQuery UI or Bootstrap have limitations but has the advantage of no more files to upload...
– Sergio
Thank you for your attention @Sergio. I will await your reply, but in parallel to this I will try to resolve also.
– João Manolo