2
I’m trying to load the contents of a modal from a remote page.
This is the code I’m using to run the tests.
$('[data-load-remote]').on('click', function (e) {
e.preventDefault();
var $this = $(this);
var remote = $this.data('load-remote');
if (remote) {
$($this.data('remote-target')).load(remote);
}
});
.modal-edit-buttom {
float: right;
font-size: 18px;
margin-right: 5px;
padding: 0;
cursor: pointer;
background: 0 0;
border: 0;
color: #000;
text-shadow: 0 1px 0 #fff;
opacity: .2;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap.min.css">
<button type="button" class="btn btn-primary" data-toggle="modal" data-load-remote="http://fiddle.jshell.net/vafleite/c5dLg852/3/show/" data-remote-target="#myModal" data-target="#myModal">Remote modal button</button>
<div class="modal hide" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">...</h3>
</div>
<div class="modal-body">
<p>...</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
And the modal that is loaded is this
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<button type="button" class="modal-edit-buttom"> <span data-load-remote="http://fiddle.jshell.net/vafleite/62m9h069/1/show/" data-remote-target="#myModal" data-target="#myModal" class="glyphicon glyphicon-edit" aria-hidden="true">Edit</span>
</button>
<h4 class="modal-title" id="myModalLabel">Header test</h4>
</div>
<div class="modal-body">Body test</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
I can load the remote modal using the method load
jQuery, the content I’m loading is a complete modal (I’ve seen some examples loading only the modal-body, but I couldn’t make it work with them either), in the header I put a button (Edit) that should (re)load the same modal but with other content, but it seems that the function of jQuery is not even called when I click this button.
I don’t know if I’ve been able to explain it well, but from the code I believe you can understand the idea better...
So @Buback, the remote modal normally loads... the problem is that from within the modal I load I try to load another modal in the same structure as the current one. Notice the code I put there in the jsfiddle that next to the close button the modal has an 'Edit'.
– Victor Leite
Imagine the following, what I carry in this modal is a user registration, then I would like to have a button inside this modal that reload this same modal but with form to edit the user data
– Victor Leite
@Victorleite, got it. I hadn’t seen Edit because of the color. I’m going to test here.
– buback
truth is really bad to see... I took most of the styles to focus more on the code, but I think it ended up getting worse a little hehe
– Victor Leite