the old dialog opens with the new dialog - jquery-ui

Hi
I am using jquery dialog box,and when I am selecting a record from atable, it call the dialog box, then when I close it and chose another record, it opens the old dialog with the new dialog... what is the problem
$(document).ready(function () {
$("#btnenterpat").click(function () {
$("#enter_payment").dialog('open');
});
$("#enter_payment").dialog({
autoOpen: false,
resizable: false,
modal: true,
width: 400,
height: 300,
buttons: {
Cancel: function () {
$(this).dialog('close');
},
ok: function () {
retur_dialog = 'ok';
$(this).dialog('close');
},
},
beforeClose: function () {
if (retur_dialog == 'ok') {
$.ajax({
url: 'ssssssss.php',
data: {
pm1: $("#pm1").val(),
pm2: $("#pm2").val(),
pm3: $("#pm3").val(),
pm4: $("#pm4").val(),
pm5: $("#pm5").val(),
pm6: $("#pm6").val(),
pm7: $("#pm7").val(),
},
});
}
}
});
});
EDIT:
First page:
<?php
include ("angela_test.php")
?>
<div style="font-size:12px;">
</div>
<br />
<table id="tbl_angela_test_data"></table>
<div id="p_angela_test_data"></div>
<script type="text/javascript">
$(document).ready(function(){
var selected_id;
var colCap = Array();
var colDef = Array();
var grp_filter = 0;
$.ajax({
url: "getColDefs.php" ,
data: {table: "bk_accounts", userid: "5", groupid: "1"},
dataType: "json",
async: false,
success: function (data) {
colCap = data[0];
colDef = data[1];
}
});
var cols = '';
for(i=0; i<colDef.length; i++) {
cols += colDef[i].name;
if (i != (colDef.length-1)) {
cols += ';';
}
}
jQuery("#tbl_angela_test_data").jqGrid({
url:'admin/angela_test_table_get.php',
postData: {columns: cols},
datatype: 'json',
mtype: 'POST',
height: 'auto',
width: 'auto',
rowNum: 20,
rowList: [10,20,30],
colNames: colCap,
colModel: colDef,
pager: "#p_angela_test_data",
viewrecords: true,
toolbar: [true, 'both'],
caption: "angela_test",
onSelectRow: function(id){
selected_id = id;
$("#angela_test_del_bnt, #angela_test_edit_bnt").attr("disabled", false);
}
});
jQuery("#tbl_angela_test_data").setGridWidth(500);
$("#t_tbl_angela_test_data").height(40);
$("#t_tbl_angela_test_data").append('<button id="angela_test_edit_bnt" style="height:30px; width:100px;" disabled="true">Edit</button>');
// edit button
$("#angela_test_edit_bnt").click(function(){
var rw = '#angela_test_item_'+selected_id;
var maintab = $("#tabs");
if ($(rw).html() != null) {
maintab.tabs('select',rw);
} else {
maintab.tabs('add',rw,'Edit form');
$(rw, '#tabs').load('admin/angelatest.php?id='+selected_id);
}
});
//////////////////////////////
})
</script>
and the second page is:
<?php
include_once("angela_test.php");
?>
<input type="button" id="btnenterpat" value="Enter Payment">
and the dialog code is:
<script type="text/javascript">
$(document).ready(function () {
$("#btnenterpat").click(function () {
$("#angela_test").dialog('open');
});
$("#angela_test").dialog({
autoOpen: false,
resizable: false,
modal: true,
width: 400,
height: 300,
buttons: {
Cancel: function () {
$(this).dialog('close');
},
ok: function () {
$(this).dialog('close');
},
},
}).parent().find(".ui-dialog-titlebar-close").hide();
});
</script>
<!--Enter Payment windows -->
<div id="angela_test" ></div>
<!--dialog windows end -->

Calling $('#some-div').dialog('destroy') would restore the #some-div element to its original form before calling $('#some-div').dialog(...). Maybe you can consider doing that upon closing the dialog?

Related

Send Jquery UI Dialog value to Url.Action

Not sure how to pass along a bool to my (working) C# method DeleteTestuser. I've Googled the heck out of this but mileage varies with all kinds of pitfalls, i.e. old information, bad syntax.
Rather than passing confirm as false, below, I need to return a bool if the user confirms the action. Thanks...
index.cshtml
<a href="#Url.Action("DeleteTestUser", "Home",
new {id = testUser.TestUserId, confirm = false})"
id="confirm-delete">
_layout.cshtml
<script type="text/javascript">
$(function () {
$('#dialog-modal').dialog(
{
title: 'Test User',
draggable: false,
resizeable: false,
closeOnEscape: true,
modal: true,
autoOpen: false,
buttons: {
'Yes': function () {
$(this).dialog('close');
confirmResult(true);
},
'No': function () {
$(this).dialog('close');
confirmResult(false);
}
}
});
$('#confirm-delete').click(function () {
$('#dialog-modal').dialog("open");
});
function confirmResult(result) { return result }
});
</script>
Basically, you're recreating your own confirm() with jQuery UI Dialog. I did this and here is a similar case: confirm form submit with jquery UI
Apply this to your scenario and you have something like:
$(function() {
function ui_confirm(message, callback) {
var dfd = $.Deferred();
var dialog = $("<div>", {
id: "confirm"
})
.html(message)
.appendTo($("body"))
.data("selection", false)
.dialog({
autoOpen: false,
resizable: false,
title: 'Confirm',
zIndex: 99999999,
modal: true,
buttons: [{
text: "Yes",
click: function() {
$(this).dialog("close");
dfd.resolve(true);
if ($.isFunction(callback)) {
callback.apply();
}
}
}, {
text: "No",
click: function() {
$(this).dialog("close");
dfd.resolve(false);
}
}],
close: function(event, ui) {
$('#confirm').remove();
}
});
dialog.dialog("open");
return dfd.promise();
}
function deleteUser(id){
// Code you will execute to delete a user or POST back.
}
$(".button").button();
$('.del').click(function(e) {
e.preventDefault();
// your code
$.when(ui_confirm("Are you sure?")).done(function(val) {
if (val) {
console.log("Delete User Confirmed.");
deleteUser($(this).attr("id"));
} else {
console.log("Do not delete user.");
}
});
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
John Smith Delete
You may be able to get away with just executing specific callbacks. That's up to you. This code can then also be used to pass along another function or to use with a prompt() like dialog.
Update
See: Using Url.Action in javascript
For example:
function deleteTestUser(uid, conf){
var url = '#Url.Action("DeleteTestUser", "Home", new {id=' + uid + ', confirm=' + conf + '})';
$.get(url, function(data){
console.log("User " + uid + " Deleted.");
});
}
I would use POST if possible.
function deleteTestUser(uid, conf){
$.post('#Url.Action("DeleteTestUser", "Home")', { id: uid, confirm: conf }, function(data){
console.log("User " + uid + " Deleted.");
});
}

Ajax displays div dialog in mvc view

Pretty new to ajax.
So I have this div:
<div id="authentication" title="Authentication" >
<b>Please Generate a new token to continue!</b>
<br /><br />
<table>
<tr>
<td>Token:</td>
<td><input type="text" id="txtToken"/></td>
</tr>
<tr>
<td></td>
<td><label id="lblError"></label></td>
</tr>
</table>
</div>
which is not being displayed on my mvc view because it is a being used as a dialogue box by Ajax code below:
$('#authentication').dialog({
autoOpen: true,
width:500,
resizable: false,
beforeclose : function() { return false; },
title: 'Authentication',
modal: true,
buttons: {
"Cancel": function () {
window.location.replace("#Url.Action("Index", "Home")");
},
"Submit": function () {
var token=$('#txtToken').val();
var dlg = $(this);
$.ajax({
type: 'POST',
data: { 'token': token},
dataType: 'json',
url: '#Url.Action("CheckNewToken", "Account")',
success: function (result) {
if(result==true)
{
window.parent.jQuery('#authentication').dialog('destroy');
}
else{
$('#lblError').html("Incorrect credentials. Please try again");
}
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
}
}
});
However when the codes goes to success and result == result, the dialog box is destroyed but the div (dialog box) is then being displayed on my view which I don't want. What am I doing wrong?
Close the dialog and then destroy. This will hide the dialog completely and then destroy its dialog features. if you just do .dialog('destroy') it will just remove the dialog functionality completely and display the element as is on the page but it wont hide.
success: function (result) {
if(result==true)
{
$('#authentication').dialog('close').dialog('destroy');
}
else{
$('#lblError').html("Incorrect credentials. Please try again");
}
},
Another thing is beforeclose : function() { return false; }, you are returning false which will prevent the close event from happening. it should be beforeClose though you can remove it safely.
if the above doesnt work another option to remove the div is by subscribing to close event:-
$('#authentication').dialog({
autoOpen: true,
width:500,
resizable: false,
title: 'Authentication',
modal: true,
close:function(){
$(this).dialog('destroy').hide();
},
buttons: {
"Cancel": function () {
},
"Submit": function () {
var token=$('#txtToken').val();
var dlg = $(this);
$('#authentication').dialog('close');
}
}
});

Tablesorter Adding Deleted Row Back In After Sorting

I'm using the jquery Tablesorter plugin and when I delete a row and then go to sort the column, the deleted row appears again. From what I've read here on stackoverflow is that I may need to add the trigger.update and/or the trigger.appendcache, but that didn't seem to work, thoug i may be placing it in the wrong place. Any ideas?
<script type="text/javascript">
$(function () {
$(".tablesorter").tablesorter({
headers: { 0: { sorter: false }, 1: { sorter: false }, 2: { sorter: false }, 3: { sorter: false} },
widgets: ['zebra'],
widgetZebra: { css: ['alt-even-class', 'alt-odd-class'] }
});
$('div#deleteDialog').dialog({
autoOpen: false,
width: 400,
height: 200,
modal: true,
position: 'center',
resizable: false,
buttons: {
OK: function () {
var delID = $('div#deleteDialog input').val();
$.post('#Url.Action("Delete", "Plate")', { id: delID }, function (data) {
if (data === 'delete') {
$('tr#' + delID).remove();
resetGrid();
}
});
$(this).dialog('close');
},
Cancel: function () {
$(this).dialog('close');
}
}
});
$('table.tablesorter thead input:checkbox').change(function () {
$('table.tablesorter tbody input:checkbox').attr('checked', $('table.tablesorter thead input:checkbox').attr('checked'));
});
$('#create').click(function () {
document.location.href = '#Url.Action("ItemSelect", "Plate")';
});
$('.menucosting_view').click(function () {
document.location.href = '#Url.Action("Details", "Plate")' + '/' + $(this).parent().parent().attr('id');
});
$('.menucosting_edit').click(function () {
document.location.href = '#Url.Action("Edit", "Plate")' + '/' + $(this).parent().parent().attr('id');
});
$('.menucosting_delete').click(function () {
$('div#deleteDialog input').val($(this).parent().parent().attr('id'));
$('div#deleteDialog').dialog('open');
});
});
function resetGrid() {
$('.tablesorter tr').removeClass('alt-even-class').removeClass('alt-odd-class');
$('.tablesorter tr:even').addClass('alt-even-class');
$('.tablesorter tr:odd').addClass('alt-odd-class');
}
Place $('.tablesorter').trigger('update'); under resetGrid();!

jquery the parent dialog textbox is locked after open dialog again

I open modal dialog twice,
the textbox is locked in the first dialog(parent dialog) after the second dialog closed
Why? How to resolve the problem? I am new user,so I can't post the image
Any answer will be appreciated, thank you
Html:
<XMP>
<input id="btnDlg" type="button" value="open dialog" />
<div id="dlg1"><%=Html.TextBox("txtName","can not edit") %><input id="btnShowDlg" type="button" value="dialog again" /></div>
<div id="dlg2"><div>the second dialog</div><%=Html.TextBox("txtName2") %></div>
</XMP>
jquery:
$("#dlg1").dialog({
autoOpen: false,
height: 350,
width: 300,
title: "The first dialog!",
bgiframe: true,
modal: true,
resizable: false,
buttons: {
'Cancel': function() {
$(this).dialog('close');
},
'OK': function() {
$(this).dialog('close');
}
}
})
$("#dlg2").dialog({
autoOpen: false,
height: 200,
width: 300,
title: "This is the second dialog!",
bgiframe: true,
modal: true,
resizable: false,
buttons: {
'Cancel': function() {
$(this).dialog('close');
},
'OK': function() {
$(this).dialog('close');
}
}
})
$("#btnDlg").click(function() {
$("#dlg1").dialog("open");
})
$("#btnShowDlg").click(function() {
$("#dlg2").dialog("open");
})
buttons: {
"Save": function () {
//validate
if (typeof (Page_ClientValidate) == 'function') {
Page_ClientValidate(newValGroup);
}
if (Page_IsValid) {
gettHTML(divID, PriceID);
}
},
Cancel: function () {
$(this).dialog("close");
}
},
close: function (ev, ui) {
$(this).dialog("destroy");
}
});
$("#" + divID).dialog('open');
return false;
Yes divid can you try Making Modal : false. it will work..
let me know..
Thanks

jQuery UI Dialog pass on variables

I'm creating a Web interface for a table in Mysql and want to use jQuery dialog for input and edit. I have the following code to start from:
$("#content_new").dialog({
autoOpen: false,
height: 350,
width: 300,
modal: true,
buttons: {
'Create an account': function() {
alert('add this product');
},
Cancel: function() {
$(this).dialog('close');
$.validationEngine.closePrompt(".formError",true);
}
},
closeText: "Sluiten",
title: "Voeg een nieuw product toe",
open: function(ev, ui) { /* get the id and fill in the boxes */ },
close: function(ev, ui) { $.validationEngine.closePrompt(".formError",true); }
});
$("#newproduct").click(function(){
$("#content_new").dialog('open');
});
$(".editproduct").click(function(){
var test = this.id;
alert("id = " + test);
});
So when a link with the class 'editproduct' is clicked it gets the id from that product and I want it to get to the open function of my dialog.
Am I on the right track and can someone help me getting that variable there.
Thanks in advance.
Set a variable eg the_id on top of everything in your script and try this code:
$("#newproduct").click(function(){
$("#" + the_id).dialog('open');
});
$(".editproduct").click(function(){
the_id = this.id;
});
Thanks Sarfraz you were right about the variable. For others interest the full code is now:
$(document).ready(function() {
var id = 0;
$("#content_new").dialog({
autoOpen: false,
height: 350,
width: 300,
modal: true,
buttons: {
'Create an account': function() {
alert('add this product');
},
Cancel: function() {
$(this).dialog('close');
$.validationEngine.closePrompt(".formError",true);
}
},
closeText: "Sluiten",
title: "Voeg een nieuw product toe",
open: function(ev, ui) { alert(id); },
close: function(ev, ui) { $.validationEngine.closePrompt(".formError",true); }
});
$("#newproduct").click(function(){
$("#content_new").dialog('open');
});
$(".editproduct").click(function(){
id = this.id;
$("#content_new").dialog('open');
});
$("#new").validationEngine();});
And on the opening of the modal dialog box i get the correct ID.

Resources