i have below function in my jsp which create and opens the dialog. There is textbox in this dalog. What i want is when i enter on this dialogue
CreateCustomer button should be licked
function createCustomerDialog(){
$("#createCustomerDialog").dialog( {
title : ""Create Customer,
buttons : {
'CreateCustomer' : function() {
},
'Cancel': function() {
$( this ).dialog( "close" );
}
}
});
$("#createCustomerDialog").dialog("open");
}
i tried this but dnot working
$('.ui-dialog-buttonpane > button:last').focus();
On dialog input's onKeyPress event check for a keycode == 13 (ENTER key), when this code is reached just click your button.
$("#yourInputId").keypress(function (e) {
if (e.keyCode == 13)
$("#yourButtonId").click();
});
May be you should use .click() method instead .focus() in this code:
$('.ui-dialog-buttonpane > button:last').focus();
And I think you should try button:first selector, because CreateCustomer button will first.
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Delete all items": function() {
$( this ).dialog( "close" );
alert('Delete all items clicked');
},
Cancel: function() {
$( this ).dialog( "close" );
alert('Cancel clicked');
}
}
});
And in browser console try this:
$('.ui-dialog-buttonpane button:first').click();
Related
Html Select Tag
<select name="testSelect" id="testSelect" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
Jquery code :-
(function () {
var previous;
$("#testSelect").on('focus', function () {
previous = $(this).val();
}).change(function() {
var r = confirm("If you change display type, default value fields will get reset !");
if (r === true) {
previous = $(this).val();
}
else {
console.log(previous);
$(this).val(previous);
}
});
})();
I am using this code to restore the previous selected value if I press No..and its working fine when I use Jquery confirm. Here Jquery confirm stops the execution when I change any value and unless I press Yes or no.
But Now I want to remove Confirm box and Want to use Jquery Dialog box for confirmation. Like this :-
$( function() {
var previous;
$("#testSelect").on('focus', function () {
previous = $(this).val();
}).change(function(event) {
var that = this;
$( "#dialog-confirm" ).dialog({
resizable: false, height: "auto", width: 400, async: false, modal: true,
buttons: {
Yes: function() {
console.log($(that).val());
previous = $(that).val();
$( this ).dialog( "close" );
},
No: function() {
$(that).val(previous);
$( this ).dialog( "close" );
}
}
});
})
} );
But here the problem is .. code gets executed even there is Dialog confirm popup. It doesnot stop like the Jquery confirm box does. I tried many stuff but not working, can anyone please help?
Remember: Everything was working fine in JQuery confirm....but not working in Jquery Dialog...
You need your code in the jQuery document ready state, so that It will get invoke only when the page is completed load and will bind your events to #testSelect.
$( document ).ready(function() {
var previous;
$("#testSelect").on('focus', function () {
previous = $(this).val();
}).change(function(event) {
var that = this;
$( "#dialog-confirm" ).dialog({
resizable: false, height: "auto", width: 400, async: false, modal: true,
buttons: {
Yes: function() {
console.log($(that).val());
previous = $(that).val();
$( this ).dialog( "close" );
},
No: function() {
$(that).val(previous);
$( this ).dialog( "close" );
}
}
});
})
});
I am implementing a password manager like chrome extension, which detect the password field and try to intercept the submit function. What I would like is:
User click "login" in a website (say Facebook). The extension content script detect the value of password and username
Ask if the user would like to store the login credentials in the manager
If yes, store the credentials.
The problem is in step 2, I was trying to prevent it from submitting until the dialog returns user action, just like any other browser built-in password manager. But apparently the preventDefault() does not work because the webpage keeps refreshing just like calling curSubmit[0].click(), which would make the dialog keep reappearing.
Is there any idea what is wrong? Part of my code is:
var inputs = document.getElementsByTagName("input");
for (var i=0; i<inputs.length; i++) {
if (inputs[i].type.toLowerCase() === "password") {
var curSubmit = $("input[type=submit]",inputs[i].closest('form'));
curSubmit[0].click(function(event){
event.preventDefault();
});
curSubmit[0].onclick = function(){
$('body').append('<div id="store-dialog" title="Store password?"><p>Do you want to store the login credentials?</p></div>');
var buttons = $( ".store-dialog" ).dialog( "option", "buttons" );
$( "#store-dialog" ).dialog({
resizable: false,
height: "auto",
position: { my: "center", at: "center", of: window },
modal: true,
buttons: {
"Yes": function() {
$( this ).dialog( "close" );
},
"Not this time": function() {
$( this ).dialog( "close" );
},
"Never": function() {
$( this ).dialog( "close" );
}
}
});
}
}
break;
}
The syntax you're using for the click handler is invalid because curSubmit[0] is not a jQuery object but a standard DOM element.
These are correct:
curSubmit[0].onclick = function(e) { ...... };
curSubmit[0].addEventListener("click", function(e) { ...... });
As for stopping try the entire artillery for both click and submit events:
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
I am trying to get the following logic to work. Any suggestions would be greatly appreciated.
here is what I'm trying to do..
if <input type="button" name="filter" id="filter" value="Save / Change" /> is clicked.
then check if requiredFields() returns true
if requiredFields() returns true
then display jQuery UI dialog
from jQuery dialog action
set form field, change form action, submit form, change form action back to original action
jQuery(function($)
{
$("#filter").on("click", function() {
if(requiredFields()) {
$("#dialog").dialog("open");
$( "#dialog" ).dialog({
resizable: false,
height:175,
modal: true,
position: {
my: "center top",
at: "center top",
of: window
},
buttons: {
"Yes": function() {
$( this ).dialog( "close" );
$('input[name="setAccess"]').val('1');
$("#myForm").attr("action", "submit.epl");
$( "form:myForm" ).submit();
$("#myForm").attr("action", "form.epl");
},
"No": function() {
$( this ).dialog( "close" );
$('input[name="setAccess"]').val('');
$("#myForm").attr("action", "submit.epl");
$( "form:myForm" ).submit();
$("#myForm").attr("action", "form.epl");
}
}
});
}
});
});
Here is Fiddle demo
I would suggest to change your workflow a bit... I would suggest to initialize modal dialog immediately on document ready event with autoOpen: false and later just use $("#dialog").dialog("open"); method to open it.
Say I have the following link:
<a onclick="confirmDelete()" href="delete.do&xyz">Delete user</a>
and the following is the confirmDelete function:
function confirmDelete()
{
if(!confirm("delete user?"))
{
return false;
} else
{
return true;
}
}
Basically when click on link, it checks whether the user select ok or cancel and then perform based on it.
Problem: I have got hundreds of similar links on my platform and we decide to turn all the javascript alerts to jquery dialog.
I used the following to somehow override the alert:
$(function(){
window.confirm = function(message) {
$('#overrideAlert').text(message).dialog({
resizable: false,
modal: true,
buttons: {
"Ok": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
};
});
It works fine and the alert comes up as a jquery dialog but the issue is because of the fact that it is not possible to return something from a handler like dialog, I am not sure how to tell my button in the filed, that the user selected ok or cancel.
Basically I m not sure how to link them all together.
Please help
The issue is because of javascript asynchronous nature . As you are using jQuery . could try following method .
$('a[onclick="confirmDelete()"]')
.attr('onclick','')
.click( function(){
var anch = this,
message = "delete user?";
$('#overrideAlert').text(message).dialog({
resizable: false,
modal: true,
buttons: {
"Ok": function() {
$( this ).dialog( "close" );
alert( "window.location=" + anch.href );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
return false ;
});
I made jsfiddle http://jsfiddle.net/wB389/
Maybe like so:
"Ok": function() {
window.location=deleteURL;
$( this ).dialog( "close" );
},
It's probably a little more complicated that that since you use relative url's but you can get the current url using window.location.protocol + window.location.port + window.location. window.location.host + window.location.pathname
I want to be able to change the title of my modal and the buttons on run time.
currently I have this
I have actions either approval or Deny
var recButton = actions =='approval' ? 'Approve' : 'Deny';
$("#dialog").dialog(
{
modal : true,
buttons : {
'update all' : function() {
// window.location.reload();
// $( this ).dialog( "close" );
//do something here
},
Cancel : function() {
$(this).dialog("close");
}
}
}); //dialog
});
I also tried to do this for button
$("#dialog").dialog(
{
modal : true,
buttons : {
recButton : function() { ...
but in modal it didn't translate well and just said recButton instead of the variable value. Also I need to change title too.
Update: got title working by simply title:
Hey Autolycus: try this man: working demo http://jsfiddle.net/C4A9b/10/
Please use firebug to check the element id / class:
$('.ui-dialog-title').html("HULK is awesome"); should do the trick.
Hope it helps :)
code
$(document).ready(function() {
$('#theLink').click(function(){
$( "#forgot-dialog" ).dialog( "open" );
});
$( "#forgot-dialog" ).dialog({
modal: true,
autoOpen: false,
height: 255,
width: 300,
buttons: {
"ChangeTitle": function() {
alert("Title before cahnge ==> " + $('.ui-dialog-title').html());
$('.ui-dialog-title').html("HULK is awesome");
// document.forms["forgotform"].submit();
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
});
});
OR
var formname = "form_name_here";
$("#ui-dialog-title-"+formname).innerHTML = "Hulk is awesome title";
Below Image show before and After.
Image before clicking changetitle button
After clicking change title