Jquery dialog box alert updation - javascript

I have a div with some content inside and as well as several options in that div area. The div and it's options click events will updated with Ajax call. I have two buttons inside this div which have to pop up different alert boxes when some thing goes wrong. One dialog box contains below options.
$("#dialog").dialog({
autoOpen: false,
resizable: true,
height: 400,
width: 150,
position: 'center',
title: 'Term Sheet',
beforeClose: function(event, ui) {
console.log('Event Fire');
},
modal: true,
buttons: {
"Submit": function() {
$(this).dialog("close");
},
"Run": function() {
Gosomewhere();
},
"Create": function() {
dosomething();
}
}
});
If i have clicked the first button and chosen the "Submit" option in the open dialog box. Next, if i click the other button which is in the div, it opens the previous dialog box instead of my new plain dialog box written inside that button event as for example,
alert("some message");// but here i get the previous dialog box with three buttons and message content as "some message"
Is there any that i can try pop up the fresh dialog box with alert in this button event?

First u try to put three different different alert for those button with different message see the message and you will found what is the problem

Related

Clicking "Check All" button in a JS dialog window results in all checkboxes in the main page being checked

Clicking a button on the main page to add a sku opens up a new window with a search field as seen in the image below. This pop-up has got a Check All button which when clicked selects all checkboxes both on the pop-up window and the main page. I don't know why it selects those on the main instead of just selecting the ones in the pop-up window.
Below is the code to select the checkboxes.
self.element.dialog({
bgiframe: true,
height: 600,
width: 838,
modal: true,
autoOpen: false,
resizable: true,
closeOnEscape: true,
title: "Add skus",
buttons: {
Cancel: function() {
$(this).dialog('close');
},
'Add Skus': function() {
self._save();
$(this).dialog('close');
},
'Check all' : function(){
$(':checkbox').attr('checked', true);
}
}
});
Try this statement:
$(':checkbox', this).attr('checked', true);
This adds context (the dialog box in this case) to the selector.

How do you prevent Modal dialog from closing when users clicks outside of the modal dialog box In JQuery UI?

I'm stuck on a old project using Jquery UI to display Modals on view. The issue that I am having is that the dialog modal view is closing when user clicks outside of Model Dialog. In Jquery is there a property to prevent this? I know that backdrop and keyboard property in Bootstrap would help in Boostrap in preventing closing of modal base on outside click but what is the case with Jquery UI?
Here's my Javascript code below:
// EDit Dialog
var updateBanquetTicketDialog = function () {
var s = $('<div></div>').dialog({
title: "Edit Banquet Ticket",
autoOpen: false,
dialogClass: "success-dialog",
modal: true,
buttons: [
{
text: "Update"
, 'class': "btn-primary"
, click: function () {
updateBanquetTicket();
}
},
{
text: "Cancel"
, 'class': "btn-warning"
, click: function () {
editBanTicketDiag.dialog('destroy');
}
}
]
});
return s;
}
I Figured it out. You must go to jquery.dialog.js file
and on line number 117 on show function replace it's code with:
var show = function () {
//call the bootstrap modal to handle the show events (fade effects, body class and backdrop div)
//$msgbox.modal('show');
$msgbox.modal({
show: true,
backdrop: 'static',
keyboard: true
});
};

How do I distinguish between a mouse click and space bar click in jquery?

I have a jquery-ui dialog box with a cancel button which closes the dialog. In this dialog box there is a page which generates a string, and sends it to a Java back end. This string contains spaces. Jquery is interpreting spaces as a click, causing my popup to close before it should.
How would I make an event for cancel button that only gets fired on a mouse click, and not a space bar?
Code:
$('<div id="popup">').dialog({
autoOpen: false,
modal: true,
buttons: {
"Cancel" : {
text: "Cancel",
id: "cancelButton",
click: function(){
$('#popup').html('');
$('#popup').dialog('close');
}
},
}
});
var close = function (event, ui) {
$('#popup').unbind("dialogclose", close);
//reload page
};
$('#popup').on("dialogclose", close);
$('#popup').load("index.html").dialog('open');

emptying text field after user inserts data for next input

I am using jquery that shows popup for input box. when the user inputs data and submits i redirected action to the same insert action so that the text field can be refreshed.at first pop up for input is shown but when i submit the popup shown previous remained as it is and new pop up for the input box is shown in which the input box is refreshed everytime i click insert.how can I close the previous popup and show only new one. and also please explain ways to empty the the textbox after user inputs data so that he can input next data.
jquery at my layout
<script type="text/javascript">
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$(".openDialog").live("click", function (e) {
e.preventDefault();
$("<div></div>")
.addClass("dialog")
.attr("id", $(this)
.attr("data-dialog-id"))
.appendTo("body")
.dialog({
title: $(this).attr("data-dialog-title"),
minWidth: 500,
minHeight: 100,
resizable: false,
close: function () { $(this).remove() },
modal: true
})
.load(this.href);
});
$(".close").live("click", function (e) {
e.preventDefault();
$(this).closest(".dialog").dialog("close");
});
});
</script>
</head>
This shows popup when i click a button to get input box
below is my jquery in insert view
</script>
<script type="text/javascript">
$(function () {
$('form').submit(function () {
$("#popUp").dialog(
{
title: $(this).attr("data-dialog-title"),
minWidth: 500,
resizable: false,
modal: true,
buttons: {
Close: function () {
$(this).dialog("close");
}
}
}
);
});
});
</script>
this shows popup for the actions that is performed from this page. ie for error message and insert another user form. Hence the popup is generated from the layout view and again next popup from insert view.I am trying to close popup from layout view when the popup from insert view is generated or some way to clear the text field in insert view without showin second popup.What should i do.
This is the line you want in the code below. I put it inline with a comment to denote but I'll put it here too for easy finding: $(this).find("input").val("");
$('form').submit(function () {
$("#popUp").dialog(
{
title: $(this).attr("data-dialog-title"),
minWidth: 500,
resizable: false,
modal: true,
buttons: {
Close: function () {
//This line below is what you need to clear the field
$(this).find("input").val("");
$(this).dialog("close");
}
}
}
);
});

Toggle view of modal button

I have the following modal dialog:
$(document).ready(function() {
$( "#addLocation" ).dialog({
modal: true,
height: 820,
width: 550,
buttons: {
"Add Location": function() {
document.forms['mapform'].submitted.value='1';
document.forms["mapform"].submit();
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
});
});
How can I toggle the 'Add Location' button? I want it to display only when a certain button within the dialog is clicked.
Thanks,
You can do it like this:
hide you add location button as soon as dialog is shown on screen. call this after the dialog open command
$("button[value='Add Location']").hide();
Then add event to the desired button that will toggle the add location button
$("buttonid or any selector").click(function(){
$("button[value='Add Location']").show();
});

Categories

Resources