I'm trying to use Intercooler with Bootstrap 4 modals. I'd like to pass some data to the modal to indicate what page to load (ideally using intercooler) and do form validation/submission inside the modal using Intercooler.
I started with this Bootstrap tutorial:
So I have this button and modal:
<button type="button" class="btn btn-secondary btn-sm float-right"
data-toggle="modal" data-target="#edit-modal"
data-xxx="XXX">Edit</button>
<div class="modal fade" id="edit-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit User</h5>
<button type="button" class="close" data-dismiss="modal">
<span>×</span>
</button>
</div>
<div class="modal-body">
<div id="edit-form">This is dynamically replaced...</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel</button>
</div>
</div>
</div>
</div>
Basically, when the modal pops up I want to load a URL with the button value appended. I haven't been able to figure out how to do that with ic-src... so currently I have this javascript that loads the form into the modal:
$(document).on('show.bs.modal', '#edit-modal', function(event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var xxx = encodeURIComponent(button.data('xxx')) // Extract info from data-xxx value
$('#edit-form').load('/edit/' + xxx) // Load the edit form
});
So my first question is there a better way to do this? Perhaps something more intercooler-ish? As mentioned above I'd like to use ic-src instead of jquery directly.
But I have a larger problem I'm stuck on now...
Inside the /edit/xxx form, I'm trying to use ic-post-to on a form field... something like this:
<input class="form-control" name="name"
ic-post-to="/edit/xxx"
ic-target="closest div"
ic-replace-target="true">
But ic-post-to is not triggered. I guess it has something to do with the manual jquery .load() call and the form input field not being present while the page loads. I'm reading about Intercooler events and the Javascript API now thinking perhaps I need to trigger some sort of refresh... But this is all pretty new to me so I'd really appreciate any help.
Thanks