Reputation: 322
I've been working on a project that requires a Semantic UI modal (pop up) to show if I click the "View Details" button, but every time the modal pops up, it is positioned weirdly and I can't do anything with it (eg can't close it)
Here is my .ejs file and the script part of it
<% include header.ejs %>
<% include nav.ejs %>
<div class="page-hero" style="background-image: url('004.jpg'); width: 100%;">
<h1 id="eachTitle">MY PROFILE</h1>
</div>
<div class="ui container">
<form method="POST">
<input type="text" name="search" placeholder="Search..." required class="searchBook">
<input type="submit" value="Search">
</form>
<% for(var i = 0; i < results.length; i++){ %>
<div class="ui grid">
<div class="column four wide">
<div class="ui card">
<div class="image">
<img src = "<%= results[i].thumbnail %>"/>
</div>
<div class="content">
<div class="header">
<h1 class="ui small header title"><%= results[i].title %></h1>
</div>
<div class="meta">
<p>Author: <%= results[i].authors %></p>
<p>Published on: <%= results[i].publishedDate %></p>
<p>Pages: <%= results[i].pageCount %></p>
</div>
</div>
<div class="content extra">
<button class="ui button fluid" id="detail">View Detail</button>
<button class="ui button fluid" type="button" name="button">Add</button>
</div>
</div>
</div>
</div>
<div id="modaldiv" class="ui modal">
<i class="close icon"></i>
<div class="header">
Book info
</div>
<div class="content">
<div class="discription">
<div class="ui header">Book Description</div>
<p><%= results[i].description%></p>
</div>
</div>
<div class="actions">
<div class="ui button">Delete</div>
</div>
</div>
<% } %>
</div>
<% include footer.ejs%>
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click', '#detail', function(){
$('.ui.modal').modal('show');
});
})
</script>
Everything is defined and the console shows no errors
(Also if I render more than one book and try to click the view details button, the page just turns black, but I think that is a loop error) Does anyone know why it happens and how I can fix it?
Upvotes: 1
Views: 1909
Reputation: 171
I think the problem comes from this loop :
for(var i = 0; i < results.length; i++).
You initialize multiples modals with the same ID and Class name so when you try to open it I think he want to open all the modals and that's not good.
$('.ui.modal').modal('show');
Try to look your console to verify it. Otherwise, create different class name or id name for each modal you create and it will be fix I think.
Peace
Upvotes: 1