I’m using bootstrap.
I’m facing a very beginner issue at displaying a modal.
Here is my code, I cannot see what i missed, what is wrong ?
So Here is my template with the button to call the modal
<template name="allCars">
<ul>
{{#each cars}}
<div class= 'car'>
<h3>{{carname}}</h3> <br>
{{#each passengers theCar._id}} <!-- Call passengers helper and put the id of the current car in parameter and then display all the names of users linked to this car -->
<p>{{username}}</p>
{{/each}}
<button class="btn btn-primary" id="add">modal</button>
</div>
{{/each}}
</ul>
</template>
Template.allCars.events({
//CLicking the button will show a modal
'click add': function(e){
e.preventdefault();
$("modalAddUserToCar").modal("show");
}
});
None of the replies above point out the initial problem and instead suggest packages Which is fine and it looks like you’ve found a solution but I thought i’d explain why your initial approach didnt work.
$('modalAddUserToCar')
Won’t ever work because its not a valid jquery selector.
You can’t refer to templates this way. Templates aren’t included in the DOM until they are used.
For a modal to be used, you need to include it in the dom. In your case somewhere in another used template or something else manualy, like the Blaze.render… methods etc. Bellow I show how to just include it.
{{>modalAddUserToCar}}
And then you have to be able to find it with a valid jquery selector. Either by ID or Class or something more complicated for example if we changed the modal template above to be: