I have a telerik popped up window. It opens fine; however, I am having an issue closing the window. If I add an alert to the javascript, alert("#Window") or alert($(this).closest('#Window')), it will display [object Object]. However, alter("#Window").data("tWindow") or alert($(this).closest('#Window').data('tWindow')) will display null. I've removed the jquery and javascript reference from either the parent or the child page, and it did not make any difference. Any kind of help would be greatly appreciated. See sample code below
Here is the popup window:
#{Html.Telerik().Window()
.Name("Window")
.Title("Student Window")
.LoadContentFrom(Url.Action("AddReason", "Reason", new { id = reasonID }, Request.Url.Scheme))
.ClientEvents(events => events
.OnClose("ClosingWindow")
)
.Draggable(false)
.Scrollable(false)
.Width(800)
.Height(600)
.Modal(true)
.Visible(false)
//.Effects(fx => fx
// .Zoom()
// .Opacity())
.Render();
}
Here is the JavaScript:
<script src="#Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript">
</script>
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/spin.min.js")" type="text/javascript"></script>
function DoOpen(id) {
var url = '#Url.Action("AddReason","Reason")';
$.post(url, { id: id }, function (data) {
var window = $('#Window').data('tWindow').center();
window.content(data);
window.open();
});
}
//This javascript is in the main page
//I did an alert. alert($('#Window')) and
alert($('#Window').data('tWindow')) they both return null
function ClosingWindow() {
$('#Window').prop("checked", "checked");
$('#Window').data('tWindow').close();
window.location.href = window.location.href;
}
Here is the partial view :
#model Student.Models.Reason
#using Student.Example
#{
ViewBag.Title = "Add Reason";
Layout = "~/Views/Shared/_PartialReason.cshtml";
}
<script type="text/javascript">
function CloseWindow() {
// alert($("#Window").closest('.t-window').data('#tWindow'));
// $("#Window").data("tWindow").close();
$('#Window').prop("checked", "checked");
window.location.href = window.location.href;
}
</script>
#using (Html.BeginForm("AddReason", "Reason", FormMethod.Post))
{
#Html.ValidationSummary(true)
<fieldset>
<div class="editor-field">
#(Html.Telerik().Editor()
.Name("EncountersArchive")
.HtmlAttributes(new { style = "height:310px;", id = "AddAReason" })
.Encode(true)
.Tools(
tools => tools
.Clear()
.Bold().Italic().Underline().Strikethrough().Subscript().Superscript().Separator()
.FontName().FontSize()
.FontColor().BackColor().Separator()
.JustifyLeft().JustifyCenter().JustifyRight().JustifyFull().Separator()
.InsertUnorderedList().InsertOrderedList().Separator()
.Indent().Outdent().Separator()
))
</div>
<p style="text-align:center">
<input type="submit" value="Reason" id="AddReasonID" onclick="CloseWindow()"/>
</p>
</fieldset>
}
The OnClose event on the popup window was causing the issue. The onclose events should only be used if the user wished to do someonthing else after the window is closed. If the purpose is simply to close the window, the Telerik control is automatically handling it. In my case, I simply remove the onclose event, and it works like a charm.
Related
I write a code that submit a form to another page without loading like ajax.I use jquery form plugin.but the problem is it is not working.
here is my code
<div id='preview'></div>
<form action='ajaxcall.php' id='upload_pic' enctype='multipart/form-data' method='post'>
<input type='file' id='pic' name='picture'>
<input type='button' id='sub'>
</form>
<script type="text/javascript" src='jqueryform.js'></script>
<script>
var options=
{
target:'#preview',
url:'ajaxcall.php',
success:function(){
document.getElementById("upload_pic").reset();
}
};
$(document).ready(function(){
$("#sub").click(function(){
$('#preview').html("<img src='images/loader.gif' alt='Loading.....'/>");
$('#upload_pic').ajaxForm(options).submit();
});
});
</script>
I understand that the ajaxForm() function is not working.the jquery file is above the code and working fine.After clicking button page automatically redirected to ajaxcall.php page.please help me finding out the error.Thanks in advance.
In this scenario you need to use ajaxSubmit
$(document).ready(function() {
var options = {
target : '#preview',
url : 'ajaxcall.php',
success : function() {
document.getElementById("upload_pic").reset();
}
};
$("#sub").click(function() {
$('#preview').html("<img src='images/loader.gif' alt='Loading.....'/>");
$('#upload_pic').ajaxSubmit(options);
});
});
Add one more submit function:
$(document).ready(function(){
$('#upload_pic').submit(function(e){ // <---pass event here
e.preventDefault(); //<----------------stop it here
});
$("#sub").click(function(){
$('#preview').html("<img src='images/loader.gif' alt='Loading.....'/>");
$('#upload_pic').ajaxForm(options).submit();
});
});
Try to stop the submit before the click.
As a marionnette beginner, I am trying to make a simple chat application using Collection and CollectionViews.
My collection won't have a fetch method since the messages only come from a particular event.
In the piece of code below my click event is not catched and I wonder why.
Should the 'send message' event be handled by the Collection view ?
Do I need to call App.chat.show(MsgListView) to display the messages ?
TBox.module("ChatApp", function(ChatApp, App, Backbone, Marionette, $, _) {
App.addRegions({
chat: "#chat-messages",
});
// Models
// ------
MsgEntry = Backbone.Model.extend({});
// Collections
// -----------
MsgCollection = Backbone.Collection.extend({
model: MsgEntry
})
// VIews
// -----
MsgView = Backbone.Marionette.ItemView.extend({
template: '#chat-entry-template',
});
MsgListView = Backbone.Marionette.CollectionView.extend({
itemView: MsgView,
events: {
"click #chat-send-btn": "handleNewMessage"
},
handleNewMessage: function(data) {
console.log("CLICK" + data);
},
});
// Init & Finalize
// ---------------
ChatApp.addInitializer(function() {
var msgCollection = new MsgCollection({});
var msgEntry = new MsgEntry({'msg': 'Hello World'});
msgCollection.add(msgEntry);
var msgListView = new MsgListView({collection: msgCollection});
});
});
HTML template
<body>
<!-- templates -->
<script type="text/template" id="status-view-template">
<div>Connecting ...</div>
</script>
<script type="text/template" id="chat-entry-template">
Hello <%= msg =>
</script>
<div id="app">
<div id="sidebar">
<div id="chat">
<h3>Chat</h3>
<div id="chat-messages">
</div>
<div id-"chat-input">
<input type="text" name="msg" />
<button id="chat-send-btn">Send</button>
</div>
</div>
</div>
<!-- main -->
<div id="page">
</div>
<div>
</body>
Ok I made it work with App.chat.show(msgListView);
Also the events hash only takes car of the ItemView events, not other dom events.
// Init & Finalize
// ---------------
ChatApp.addInitializer(function() {
App.vent.trigger("app:started", "ChatApp");
var msgCollection = new MsgCollection([{foo :'bar', foo: 'lol'}]);
var msgListView = new MsgListView({collection: msgCollection});
// render and display the view
App.chat.show(msgListView);
});
when a submit button is clicked i want to generate a pop up showing the list of items. The code i tried to create pop up is as follows:`
Index View:
<script type="text/javascript">
$('#popUp').Hide();
$('#button').click(function () {
$('#popUp').click();
});
</script>
<div class="left-panel-bar">
#using (Html.BeginForm(FormMethod.Post))
{
<p>Search For: </p>
#Html.TextBox("companyName",Model);
<input id="button" type="submit" value="Submit" />
}
</div>
<div id="popUp">
#Html.ActionLink("Get Company List", "CreateDialog", "Company", null, new
{
#class = "openDialog",
data_dialog_id = "emailDialog",
data_dialog_title = "Get Company List"
});
</div>
but i got trouble using this code.. when i click the submit button it opens another page instead of popup. The controller code is as follows:
[HttpPost]
public ActionResult Index(Companies c)
{
Queries q1 = new Queries(c.companyName);
if (Request.IsAjaxRequest())
return PartialView("_CreateDialog", q1);
else
return View("CreateDialog", q1);
}
You could use AJAX:
<script type="text/javascript">
$(function() {
$('form').submit(function() {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function(result) {
$('#popUp').html(result);
}
});
return false;
});
});
</script>
<div class="left-panel-bar">
#using (Html.BeginForm())
{
<p>Search For: </p>
#Html.TextBox("companyName", Model);
<input id="button" type="submit" value="Submit" />
}
</div>
<div id="popUp">
</div>
Now ehn the form is submitted, an AJAX request will be sent to the Index POST action and since inside you test if the request was an AJAX request it will return the _CreateDialog.cshtml partial view and insert it into the #popUp div. Also it is important to return false from the form submit handler in order to cancel the default even which is to redirect the browser away from the current page.
It's my first time using partial views and I am unable to get the actual partialview. The ajax function gets called, the controller gets hit, and an alert in the ajax call shows me that the partialview is there. But, with errors written to the console (or alert) my div remains just as empty.
My application is an MVC4 app, but I am pretty sure I've just done a silly mistake somewhere and its not MVC's fault :)
AFter a few hours of googling, I would really be happy anybody can help me get this working, and all tips/comments on code/ajax i greatly appreciated!
public PartialViewResult Groups()
{
var person = _userRepository.GetCurrentUser();
var connections = (from c in person.Person1 select c).ToList();
var groups = _context.Groups.Where(g => g.GroupId == 1);
var all = new GroupViewModel()
{
Connections = connections,
GroupDetailses = (from g in groups
select
new GroupDetails
{
Name = g.Name,
StartDate = g.StartDate,
StartedById = g.StartedById,
})
};
return PartialView("Groups",all);
}
My PartialView
#model Mvc4m.Models.GroupViewModel
<h2>Groups</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
<h3>Create new Group</h3>
<div class="ui-widget">
<label for="group">Groupname: </label>
<input id="group" />
<button onclick="addGroup()">Add</button>
</div>
#foreach (var item in Model.GroupDetailses)
{
#Html.LabelFor(model => item.Name)<text> : </text>
#Html.DisplayFor(model => item.Name)
}
<script>
function addGroup() {
$.get(
"/Profile/AddGroup",
{
Name: $("#group").val()
});
location.reload();
};
</script>
My Ajax call on Profile/Index
#model Mvc4m.Models.ProfileView
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div id="test" style="background-color:Aqua; width:200px; height:100px"></div>
<button onclick="load()"></button>
<script type="text/javascript">
function load() {
$.ajax({
type: "GET",
url: '/Profile/Groups',
dataType: 'html',
success: function (response) {
$('#test').html(response);
alert(response);
},
error: function (xhr, status, error) {
alert(status + " : " + error);
}
});
}
</script>
Turns out the code works, a restart of visual studio did the trick! How I hate VS sometimes...
I have developed a MVC3 application in that I want use the Check boxlist in this I have three check boxes. My requirement is when I check the check box it accept only on check box not multiple remaining check box should be unchecked like RadioButton list type.
Please help me... How can I resolve this problem?
Here is my view code
#{
ViewBag.Title = "MenuCategories";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
$(function () {
enable_cb();
$("#ChbkPickup").click(enable_cb);
});
function enable_cb() {
if (this.checked) {
$("input.ccc").removeAttr("disabled");
} else {
$("input.group1").attr("disabled", true);
}
}
$(function () {
$('.example-container > pre').each(function (i) {
eval($(this).text());
});
});
</script>
#using (Html.BeginForm("OrderCompleted", "Home", FormMethod.Post, new { id = "myForm" }))
{
#Html.ValidationSummary(true)
Delivery:<input type="checkbox" name="Deliver" value="Deliver" id="Chbkdeliver" />
Pickup: <input type="checkbox" name="Deliver" value="Pickup" id="ChbkPickup" class="group1" checked="checked" />
Dine In:<input type="checkbox" name="Deliver" value="Dinein" class="group1" id="ChbkDinein" />
}
replace all your javascript tag with this
<script type="text/javascript">
$(function () {
$("#myform :checkbox").click(function(){
$("#myform input:checked").attr("checked","");
$(this).attr("checked","checked");
});
});
</script>