JQuery UI Dialog submit form with multiple form inputs - jquery-ui

I have a form with three inputs: Save, Delete, and Exit. When Delete is clicked, I pop a JQuery UI Dialog box to confirm that the user wants to delete that data. They have two buttons as options: Delete or Cancel. Cancel works fine and closes the Dialog box. If they click Delete, I wish to submit the original form and delete the data as if the Dialog box was not there, which is not working. I click it and nothing appears to happen.
I am attempting to submit the "update_purchase" form but simulate using the "delete_purchase" input to convey information. With the below code, once I click "Delete" on the Dialog box nothing happens; however, if I click "Cancel" to exit the dialog box and then click "Exit" on the original form, I find the entry has been deleted.
Thanks for any and all help.
<form method="post" id="update_purchase" enctype="multipart/form-data" action="{{ url }}">
...
<input type="Submit" name="save" value="Save">
<input type="Submit" name="delete_purchase" id="delete" value="Delete">
<input type="Submit" name="exit_edit" value="Exit">
// Confirm Delete dialog
$(function() {
$("#dialog").dialog({
autoOpen: false,
resizable: false,
height: 180,
modal: true,
buttons: {
"Delete": function() {
$("#update_purchase").submit( function(eventObj){
$('<input />').attr('type', 'hidden')
.attr('name', "delete_purchase")
.attr('value', "Delete")
.appendTo('#update_purchase');
$( this ).dialog( "close" );
return true;
});
},
"Cancel": function() {
$( this ).dialog( "close" );
}
}
});
$("#delete").click(function() {
$("#dialog").dialog("open");
return false;
});
});

Related

why won't my jquery dialog fully fadeOut()?

When I call fadeOut on my dialog it only does a partial fade and leaves the grey header area where the dialog title is. I've tried removing the title as well as the various attributes that disable the exit button in the upper right corner of the dialog, but that didn't work. As you'll see in my script below, I want the dialog to close after the form submission has been validated.
//HTML
<div id="dialog">
<form id="form">
<p id="thanks">Please provide a contact number. It will only be shared with the
host</p><input id="number" name="number" type="text"/>
<button id="submit" type="submit">Submit</button>
</form>
</div>
//JS
if(myConditional){
//FORM IS HIDDEN ON PAGE LOAD AND SHOWN ON CLICK
$('form').show();
$('#dialog').dialog({
//These parameters are meant to disable the dialog close button
closeOnEscape: false,
beforeclose: function (event, ui) { return false; },
dialogClass: "noclose",
title: "Thanks For Volunteeering",
minWidth: 500
});
$('button').button();
}else{
//other code
}
//Validate the phone number before saving it to local storage
$("#form").validate({
rules: {
number : {
required: true
customvalidation: true
}
},
messages: {
number : {
required: "enter a phone number"
}
},
submitHandler: function(form) {
var number = $('#number').val();
localStorage.setItem('number', JSON.stringify(number));
//THIS FADE OUT ISN'T FULLY FADING THE DIALOG
$('#dialog').fadeOut();
} //closes submit handler
});//close validate
Ok I figured it out.
I got rid of the beforeClose parameter in the dialog init code, and in the form validation submit handler I added this:
$('#dialog').fadeOut('slow', function(){
$( this ).dialog( "close" );
});
//The fadeOut method has a call back function you can use with it to do something after the fade is completed.

Transfer Ajax data to hidden textbox in mvc

I have the folloing textboxes located in a form:
<input type="text" id="duration" name="duration" readonly="readonly" style="width:0px"/>
<input type="text" id="renew" name="renew" readonly="readonly" style="width:0px"/>
<input type="text" id="accountAfter" name="accountAfter" readonly="readonly" style="width:0px"/>
On form post these text boxes will pass the data to the controller retrieved from the following dialog:
$('#fixed').dialog({
autoOpen: false,
width:600,
resizable: false,
title: 'Fixed Account Details',
modal: true,
buttons: {
"Close": function () {
$(this).dialog("close");
},
"OK": function () {
$('#duration').val($('#duration').val());
$('#renew').val($('#renew').is(':checked'));
$('#accountAfter').val($('#accountAfter').val());
$(this).dialog("close");
}
}
});
Is it possible hide these textboxes from the user whilst still passing data?
Change them to hidden input elements. For example:
<input type="hidden" id="duration" name="duration" />
I think the rest of your code can stay the same, although I'm not really sure what you're trying to accomplish here; you're just updating the the values to themselves.
$('#duration').val($('#duration').val());
$('#renew').val($('#renew').is(':checked'));
$('#accountAfter').val($('#accountAfter').val());

How to hide this "close" button

I am using this jquery-ui to display a dialog box but it comes with a freebee named as "close" which I don't want,
you can find rest of code here, Why my Dialog box isn't working
In html its coming up as
<a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button">
<span class="ui-icon ui-icon-closethick">close</span>
</a>
Did you look at the documentation?
http://api.jqueryui.com/dialog/
Hiding the close button
In some cases, you may want to hide the close button, for instance, if
you have a close button in the button pane. The best way to accomplish
this is via CSS. As an example, you can define a simple rule, such as:
.no-close .ui-dialog-titlebar-close { display: none; }
Then, you can simply add the no-close class to any dialog in order to hide it's
close button:
$( "#dialog" ).dialog({ dialogClass: "no-close", buttons: [
{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
} ] });

pass variable to jquery dialog

I am wanting to pass a variable to a jquery dialog window. I am using classic ASP and have onyl really touched on the world of jquery. I have spent a few hours researching and tring to use the .data method but are having trouble. Your time and assitance would be very much apriciated!
Here is my stripped down page:
$(function(){
// Dialog
$('#dialog').dialog({
autoOpen: false,
show: "slide",
hide: "fade",
width: 452,
modal: true,
buttons: {
"Ok": function() {
PostItNote.submit();
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
// Dialog Link
$('#dialog_link').click(function(){
$('#dialog').dialog('open');
return false;
});
});
and this is how I call the window:
<a href='#' id='dialog_link' CLASS='OrangeButton'> Show Window </a>
and the contents of my window:
<div ID="dialog" TITLE="Periodic Report">
stuff here
</div>
Why can I not do this:
<a href='#' id='dialog_link(someValue)' CLASS='OrangeButton'> Show Window </a>
Thank you in advance
How it is used in the ASP loop is:
do until Products.EOF
--other code here---
<a href='#' id='dialog_link(Products(0))' CLASS='OrangeButton'>
--other code here---
products.moveNext
loop
The dialog is just a div on your page, so it can't really be "passed" a value. It can be manipulated by any JavaScript variables in scope though. You could change your click handler to use a variable to manipulate the dialog:
var myVariable = "Some new text for the dialog";
$('#dialog_link').click(function(){
//New code to "pass" a value to the dialog
$('#dialog').text(myVariable);
$('#dialog').dialog('open');
return false;
});
Or you could use the open member of the dialog:
...
width: 452,
open: function() { $('#dialog').text(myVariable); },
modal: true,
...
To make changes to the dialog div whenever it is opened.
The code id='dialog_link(someValue)' will not do anything, as the id attribute cannot make function calls, only event handlers like onchange can do that. Even if it could, dialog_link is not a function that can be passed a value. It is just the id of another element.
I'm sure you're probably already aware, but the jQuery documentation is very useful- here are the docs for dialog.
Edit
In response to your comment: I would drop the $('#dialog_link').click(); statement and change the link code to the following:
<a href='#' class='OrangeButton' onclick='openDialog(someValue);'>Show Window</a>
And then add the JavaScript function to be called on the click event:
function openDialog(value) {
$('#dialog').text(value);
$('#dialog').dialog('open');
}
Edit 2
Inside of the ASP loop something like this should do the trick:
Response.Write("<a href='#' onclick='openDialog(" & Products(0) & ");'>Show</a>")
This will create an <a></a> element on the page with an onclick handler that passes the desired value to openDialog, making it accessible by the dialog.
I changed the code for the link slightly so that it all fit on one line, but you could always add back the class='OrangeButton' and all that if you'd like.

JqueryUI Dialog. Unable to trigger from html form

Works fine with a text link to fire dialog - but lasts for about .5 second if triggered from an html form submit button. Sounds crazy! Yep, just cannot get it to work. Help!
$(document).ready(function() {
$('#rating-0').click(function() { $('#dialog').dialog('open'); }); $('#dialog').dialog({ autoOpen: false, height: 280, modal: true, resizable: false, buttons: { Continue: function() {
$(this).dialog('close'); // Submit Rating
}, 'Change Rating': function() {
$(this).dialog('close'); // Update Rating
} }
});
});
<form action="https://www.etc" id="rating-0">
<input type="hidden" name="cmd" value="_s-xclick" />
<input name="submit" type="image" src="https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif" />
</form>
<div id="dialog" title="Are you sure?">
<p>You've assigned the current celebrity a rating of 0…</p> <p>Perhaps you are just judging them on the terrible last movie…</p>
</div>
Add return false; to your submit or click handler to prevent the browser from submitting the form and reloading the page.
EDIT:
$(document).ready(function() {
$('#rating-0').submit(function() {
$('#dialog').dialog('open');
return false;
});
...
});

Resources