Bootstrap modal for edit not openning. ASP.Net-MVC - asp.net

I need to make a Modal for editing a player, and I made one, but whenever I click button "Change" it doesen't open my modal. I don't know where am I supposed to send the right ID
this is my jquery
var data= 0;
$('.btnEdit').click(function () {
$('#myModalEdit').modal("show");
});
$('#myModalEdit').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
data= button.data("playerId");
});
To be precise, when I click Change it does enter the first function, but doesn't open modal. I would really need help. If you need more info, please write what, and I will post it.
Modal code:
<!--Modal-->
<div id="myModalEdit" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Ucinak igraca</h4>
</div>
#Html.HiddenFor(Model => item.IgracId)
<div class="col-md-6">
#Html.LabelFor(Model => item.ImeIPrezime)<br />
#Html.LabelFor(Model => item.OdigraneMinute)<br />
#Html.LabelFor(Model => item.PostignutiGolovi)<br />
#Html.LabelFor(Model => item.ZutiKarton)<br />
#Html.LabelFor(Model => item.CrveniKarton)
</div>
<div class="col-md-6" style="margin-bottom:5px;">
#Html.DisplayFor(Model => item.ImeIPrezime)<br />
#Html.EditorFor(Model => item.OdigraneMinute)<br />
#Html.EditorFor(Model => item.PostignutiGolovi)<br />
#Html.EditorFor(Model => item.ZutiKarton)<br />
#Html.EditorFor(Model => item.CrveniKarton)
</div>
<div class="modal-body" id="modal-body">
<div id="greska"></div>
</div>
<div style="align-content:center">
<br />
<button type="button" class="btn btn-primary" data-dismiss="modal" id="sacuvaj">Sacuvaj</button>
<button type="button" class="btn btn-primar" data-dismiss="modal" id="odustani">Odustani</button>
</div>
</div>
</div>
</div>
<!--Modal-->
Button code:
<button type="button" class="btn btn-primary" data-igracId="#item.playerId" id="Edit" data-target="#myModalEdit" data-toggle="modal">Izmjeni</button>

Could you please Add class "btnEdit" to your Button
like this
class="btn btn-primary btnEdit"
Your button is missing the class btnEdit so related click event not getting executed
replaace
<button type="button" class="btn btn-primary" data-igracId="#item.playerId" id="Edit" data-target="#myModalEdit" data-toggle="modal">Izmjeni</button>
with
<button type="button" class="btn btn-primary btnEdit" data-igracId="#item.playerId" id="Edit" data-target="#myModalEdit" data-toggle="modal">Izmjeni</button>
And make sure script gets exexutes html rendering done
Sometimes when dynamic html is rendered events are not mapped
if its case ADD onclick="$('#myModalEdit').modal('show');" to you BUTTON

Related

ASP.NET modal cannot display model props

I have a problem: I pass a collection to a view. Then I iterate through it and display some data. In normal markup, it works, but in modal it doesn't. Please tell me why modal code does not show the data.
Here is the view:
#model IEnumerable<Models.ToDO>
#foreach (var item in Model)
{
#if (item.isDone == true)
{
<div class="done-element element">
<p>
Title: #Html.DisplayFor(modelItem => item.Title)
</p>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>
Description: #Html.DisplayFor(modelItem => item.Desc)
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
}
}
EDIT: I found some strange things: all modals display this value, but all take it from the first element
EDIT2: I found the solution. Target data is ID and take first found element. Changing ID to variable fix problem.

Multiple Bootstrap Modals and postbacks

My knowledge in ASP.NET is very limited, yet, I am building a UI/UX design for an application that will be built in ASP MVC and I've heard rumors of the following problem:
When a Boostrap modal fires a button event (onClick), it creates a postback which in turn, it refreshes the page, thus making it impossible for multiple bootstrap modals to work. Unless the modals do not require to interact with the back end, which means they would simply serve a client-side purpose.
I need to know how much of this is true and if there is a way to create a search or populate a bootstrap modal with information being entered in a second modal.
Unfortunately, I can't produce a working ASP code but I will produce the HTML portion of it so you have an idea.
Again, my question is, can I populate modal 1 with information entered in modal 2? Modal 2 is invoked from Modal 1. See the code and Demo for details
<div class="container">
<h1>Working with Multiple Modals</h1>
<div class="margin-lg">
<button type="button" class="btn-first-modal btn btn-primary btn-lg" data-toggle="modal" data-target="#first-modal">
Launch Modal
</button>
</div>
<div class="modal" id="first-modal" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<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>
<h4 class="modal-title" id="myModalLabel">First Modal</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-xs-12 col-sm-4">
<label class="label-control">My ID</label>
<input type="text" class="form-control" disabled/>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn-second-modal within-first-modal btn btn-primary">
Add ID
</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal" id="second-modal" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn-second-modal-close close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">ID Generator</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-xs-12 col-sm-4">
<label class="label-control">Choose ID</label>
<input type="text" class="form-control" />
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn-second-modal-close btn btn-primary">Add</button>
</div>
</div>
</div>
</div>
JS
var within_first_modal = false;
$('.btn-second-modal').on('click', function() {
if ($(this).hasClass('within-first-modal')) {
within_first_modal = true;
$('#first-modal').modal('hide');
}
$('#second-modal').modal('show');
});
$('.btn-second-modal-close').on('click', function() {
$('#second-modal').modal('hide');
if (within_first_modal) {
$('#first-modal').modal('show');
within_first_modal = false;
}
});
$('.btn-toggle-fade').on('click', function() {
if ($('.modal').hasClass('fade')) {
$('.modal').removeClass('fade');
$(this).removeClass('btn-success');
} else {
$('.modal').addClass('fade');
$(this).addClass('btn-success');
}
});
DEMO
This would let you make a request to the server and do something with the information that you get back.
$(".btn-second-modal").on("click", function () {
$.ajax({
url: "/urltoserver/action/",
cache: false
}).done(function (data) {
// SET YOUR FIRST MODAL PROPERTIES
// HIDE YOUR SECOND MODAL
// SHOW YOUR FIRST MODAL
});
});

bootstrap-modal two instances

I was able to load external content to my bootstrap-modal , but every time i call the modal page it creates an extra instance, see this screenshot
user (https://dl.dropboxusercontent.com/u/67763500/modal%20issue.PNG)
how to troubleshoot this? I believe it's on the CSS, but not sure where exactly.
here are my views code:
<div id="responsive" class="modal fade" tabindex="-1" data-width="760" style="display: none;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Info</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
#*<button type="button" class="btn btn-primary">Save changes</button>*#
</div>
Click me !
and here is the code for the target modal
<div class="modal-body">
<dl class="dl-horizontal">
<dt>
#Html.DisplayName("User Name")
</dt>
<dd>
#ViewBag.username
</dd>
<dt>
#Html.DisplayNameFor(model => model.Name_Prefix)
</dt>
<dd>
#Html.DisplayFor(model => model.Name_Prefix) .
</dd>
</dl>
<p>
#*#Html.ActionLink("Edit", "Edit", new { id = Model.CustomerId }) |*#
<button type="button" data-dismiss="modal" class="btn btn-default">Close</button>
</p>
I figured it out. It was another script on my page that caused the issue.
I removed it and it works like a charm.

Bootstrap Modal Pop up not firing

So I am working a web project and hoping to use Bootstrap Modal Pop up. I implemented the codes but unfortunately my modal wont fire. I am using Visual Studio 2012 by the way.
I have included the following:
<script src="jquery/jquery-ui-1.10.4.custom.min.js"></script>
<script src="jquery/bootstrap.js"></script>
Here is my trigger for the modal:
<asp:Button ID="btnAddEvent" data-toggle="modal" data-target="#myModal" class="btn btn-default" runat="server" Text="Add Event" />
And here is my modal:
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</p>
</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>
</div>
include the jQuery script before the bootstrap.js script file for the plugin to work.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
jquery/jquery-ui-1.10.4.custom.min.js
jquery/bootstrap.js
typo error 'jquery' folder or 'js' folder
DEMO

Watir webdriver_unable to click Cancel Target button on popup window

I am VERY new to Watir, trying to test a popup window and am unable to get my script to click the Cancel Target button. When running the script, I get an error: element not visible (Selenium::WebDriver::Error::ElementNotVisibleError. This is the script I am using:
browser.div(:class => "modal-footer").button(:class => "btn btn-danger").click
Below is the code:
<div class="modal hide fade" id="target_modal" data-bind="with: target">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 data-bind="text: BusinessName"></h3>
</div>
<div class="modal-body">
<div class="row">
<div class="span3">
<label for="FirstName">First Name</label><input id="FirstName" type="text" data-bind="value:FirstName" />
<label for="LastName">Last Name</label><input id="LastName" type="text" data-bind="value: LastName" />
<label for="Email">Email</label><input id="Email" type="text" data-bind="value: Email" />
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-bind="click: saveTarget">
<i class="icon-white icon-ok"></i>
Save Target
</button>
<button class="btn btn-danger" data-dismiss="modal">
<i class="icon-white icon-remove"></i>
Cancel Target
</button>
</div>
</div>
Any help would be greatly appreciated. Thanks!
I assume that this popup is part of the page (ie just an div tag overlaying the rest of the page), rather than a new browser window popup.
My guess is that Watir is trying to click the button before the popup finishes being displayed. Explicitly telling Watir to wait for the button may solve the problem:
cancel_button = browser.div(:class => "modal-footer").button(:class => "btn btn-danger")
cancel_button.when_present.click
I got it to work. Justin Ko's 1st answer got me thinking and this worked:
cancel = browser.div(:id => "target_modal")
cancel.div(:class => "modal-footer").button(:class => "btn btn-danger").i(:class => "icon-white icon-remove").click

Resources