Here's my function:
function confirmFamilyMemDelete()
{
$('#dialog').attr('title', 'Warning').text('Are you sure?').dialog({ buttons:
[{
text: 'Yes',
click: function ()
{
$('#MainContent_cph_btnConfirmDelete').click();
$(this).dialog('close');
alert('Hello');
}
},
{
text: 'No',
click: function ()
{
$(this).dialog('close');
}
}
]
});
return false;
}
I've got a very weird problem. In my aspx page there's a button that gets an id 'MainContent_cph_btnConfirmDelete' after it gets rendered. I want to click it if Yes button is clicked in the jQuery UI dialog. However, I fail to do it. It just skips over that command and alerts 'Hello'. This means the rest of the code inside my Yes button gets executed. And if I take
$('#MainContent_cph_btnConfirmDelete').click();
out and put it just before return false; the button gets clicked. Is this a know issue with jQuery because I can't think of any logical explanation. If so, what is the workaround?
Here is what I think you need:
function confirmFamilyMemDelete()
{
$('#dialog').attr('title', 'Warning').text('Are you sure?').dialog({ buttons:
{
"Yes": function ()
{
$('#MainContent_cph_btnConfirmDelete').trigger('click');
$(this).dialog('close');
alert('Hello');
},
"No": function ()
{
$(this).dialog('close');
}
}
});
return false;
}
Related
When a modal window is started, there will be no form validation if you use the default way:
$('#someModalWindow')
.modal({
inline: true,
onDeny: function () {
// someting
},
onApprove: function () {
// some action
}
})
.modal('show');
How can a form validation be triggered manually or automatically in the modal window.
I am using meteor below SemanticUI
thanks
I figured out how to do it:
$('#someModalWindow')
.modal({
onDeny: function () {
// someting
},
onApprove: function () {
var validated = $('#myFormId').form('validate form');
if(!validated){
return false;
}
// some action
}
})
.modal('show');
hopefully this can help you.
I want to alter how an asyncCommand is being hit (currently from a button), so I would need to access the asyncCommand from code. I don't want to have to alter what this asyncCommand is doing, it is dealing with payment details.
I have tried Googling but I cant find anything, I am also new to KO.
This is what I'm trying to achieve:
Click on a button (a separate button with its own asyncCommand method
which checks a flag) The 'execute' will do the following:
If (flag) - show modal
modal has two options - Continue / Cancel
If continue - hit asyncCommand command for original button (card payment one).
If cancel - go back to form
If (!flag)
Hit asyncCommand command for original button (card payment one).
Can this be done?
Thanks in advance for any help.
Clare
This is what I have tried:
FIRST BUTTON
model.checkAddress = ko.asyncCommand({
execute: function (complete)
{
makePayment.execute();
if (data.shippingOutOfArea === true || (data.shippingOutOfArea === null && data.billingOutOfArea === true)) {
model.OutOfArea.show(true);
}
complete();
},
canExecute: function (isExecuting) {
return !isExecuting;
}
});
ORIGINAL BUTTON
model.makePayment = ko.asyncCommand({
execute: function (complete) {
}})
MODAL
model.OutOfArea = {
header: ko.observable("Out of area"),
template: "modalOutOfArea",
closeLabel: "Close",
primaryLabel: "Continue",
cancelLabel: "Change Address",
show: ko.observable(false), /* Set to true to show initially */
sending: ko.observable(false),
onClose: function ()
{
model.EditEmailModel.show(false);
},
onAction: function () {
makePayment.execute();
},
onCancel: function ()
{
model.EditEmailModel.show(false);
}
};
You will have two async commands actually for this scenario. One to open up the modal and another one for the modal.
Eg:
showPaymentPromptCmd = ko.asyncCommand({
execute: function(complete) {
if (modalRequired) {
showModal();
} else {
makePayement();
}
complete();
},
canExecute: function(isExecuting) {
return !isExecuting;
}
});
//Called by Continue button on your modal.
makePaymentCmd = ko.asyncCommand({
execute: function(complete) {
makePayement();
complete();
},
canExecute: function(isExecuting) {
return !isExecuting;
}
});
var
function makePayement() {
//some logic
}
JqueryUI:
The code below fires an alert every time the box is closed, but how can I make it so it only does this for once and not every time.
$("#box").dialog({
close: function () {
alert(999);
}
});
This was how I did it before using jQueryUi:
$("#box").one("click", function () {
alert(999);
return false
});
According to the docs, the .close() method also has a corresponding event: dialogclose. So you should be able to do this:
$("#box").one("dialogclose",function() {
alert(999);
});
I have the code below that shows a throbber and makes a getJSON call to an MVC action when the user changes an entry in a select. This all works great except there is a default -- select -- element in the list for which I don't want the getJSON to run.
However, I can't work out how to apply conditional logic to hooking this event. The conditional logic is shown as the if(selectedValue == -1) But the throbber still runs as I've hooked it in the first line. I've tried removing the first line that hooks the change event and use $.throbberShow(..) inline just prior to the getJSON call but for some reason this doesn't show the throbber.
Any help greatly appreciated.
$("#selectlist").throbber("change", { ajax: false, image: "images/ajax-loader-line.gif" });
$("#selectlist").change(
function () {
var selectedValue = $("#selectlist").val();
if (selectedValue != -1) {
//Tried doing $.throbberShow(...) here without success
$.getJSON("/Candidate/GetAddress", { id: selectedValue }, function (data, textStatus) {
if (textStatus == "success") {
$("#selectlist").val(data.Line1)
$("#selectlist").val(data.Line2)
$("#selectlist").val(data.Line3)
$("#selectlist").val(data.Town)
}
$.throbberHide();
});
}
}
);
It is more a hack than a solution as throbber doesn't support conditions but this should work:
$("#selectlist").throbber("change", { ajax: false, image: "images/ajax-loader-line.gif", delay: "500" });
$("#selectlist").change(
function () {
var selectedValue = $("#selectlist").val();
if (selectedValue != -1) {
$.getJSON("/Candidate/GetAddress", { id: selectedValue }, function (data, textStatus) {
if (textStatus == "success") {
$("#selectlist").val(data.Line1)
$("#selectlist").val(data.Line2)
$("#selectlist").val(data.Line3)
$("#selectlist").val(data.Town)
}
$.throbberHide();
});
} else {
$.throbberHide();
}
}
);
i've got a page (asp.net) where I trap the click event of a link.
i then do some dirty checking and present a dialog to the user,
$(function() {
var clickedLink;
$('.checkdirty').click(function(event) {
if(isDirty == false){
return true;
}
clickedLink = $(this);
$('#dirtysave-dialog').dialog('open');
return false;
});
});
do you want to loose your changes Yes/No etc.
$('#dirtysave-dialog').dialog({ bgiframe: true, autoOpen: false,
height: 125, width: 425, modal: true,
title: "You have unsaved changes, do you want to continue and loose changes?!!",
buttons: {
"Yes": function() {
isDirty = false;
$(this).dialog("close");
$(clickedLink).click();
},
"No": function() {
$(this).dialog("close");
}
},
open: function(type, data) {
$(this).parent().appendTo("form");
}
});
if they click yes i then clear the isDirty flag and call click on the link. this goes back in to the click event handler, does the check
if(isDirty == false){
return true;
}
returns true but the event never happens....
i need to click the link again manually for it to fire.
any ideas??
.click() only fires the event handlers for onclick, it doesn't actually make the default action of following the link happen. Probably the quickest method is just to do that manually:
window.location= clickedLink.href;
PS. “lose”
you can use the trigger function, Change:
$(clickedLink).click();
to
$(clickedLink).trigger("click");
A better way would be to separate your click functionality out into a separate function and call this, however the above will work.