The avid Impromptu enthusiast will be much pleased with the advancement of using events. Not only does 4.0 bring more events, it also brings better events. First and foremost I must point out there is a change to the state’s submit parameters. The first parameter is now an jQuery.Event, followed by the original 3 parameters from older versions. For backwards compatibility you can find on Github a tag for 3.3.3 which was committed with the new events, but with backwards compatibility of keeping the original parameters for the classic style of passing the submit option during the $.prompt call.
Ok, so why the change?
- So far with Impromptu you had to return true/false inside the submit callback to tell Impromptu whether or not to close the prompt. You can still do this, however the more appropriate way is to use the first parameter to call event.preventDefault() to prevent the prompt from closing. Think of it as how you would treat an anchor tag’s click event.
- You can call event.stopPropagation() to prevent event bubbling.
- You can now bind as many events as you like, though only one may be passed in the $.prompt() options.
- More events available through the same interface.
In addition to the change of how events work, there were additional events. Here are all available events:
- promptloaded: called when the prompt has been displayed. Parameters (event)
- promptsubmit: called on button click. Parameters (event, value, message, formVals)
- promptclose: same as callback option. Called when prompt has closed. Parameters (event[, value, message, formVals]). Optional parameters are only available when a button was clicked.
- promptstatechanging: called before state change. return false or event.preventDefault() stops the state change. Parameters (event, fromStateName, toStateName)
- promptstatechanged: called after the state change is complete. Parameters (event, stateName)
Now you want to see what the difference is. Lets look at a quick example. I must mention you can still call $.prompt just like before, but just consider these changes “Extras”.
var jqi = $.prompt('Hello World!');
jqi.bind('promptsubmit', function(event, val, msg, fields){
// To hold the prompt open you can either:
// event.preventDefault()
// or
// return false;
});
Pretty straight forward. Again you can still use the submit, loaded, and callback options just like before with the exception of adding the event parameter first. Feel free to share your opinions!


20 Responses
Najib
May 14, 2012Hi there,
I´m trying to use impromptu with 2 different languages, but i dont know how to set button labels for each language.
could you help me please ?
thanks in advance.
shaan
May 31, 2012how can i use impromtu to send data to server using ajax
Christian ventez
Jul 03, 2012Hey, first of all…thanks a lot! your improptu saved my life but i had a problem.
in the website i created i create an iframe to watch youtube videos….when i activate the modal window, the i frame blocs the modal window and i can`t see, big part of its content…how to correct this
Chris
Jul 27, 2012Hey, first off this seems to be a great utility…but at the moment I am having trouble getting the prompt.close function to work. Everything is fine but using that function does nothing, seems like the fade goes a little but the prompt stays model and the controls are still active.
Thanks
C
trent
Jul 27, 2012Do you have any events that may be preventing it from closing? Any errors?
Chris
Aug 06, 2012No errors and no events.
Chris
Aug 06, 2012It seems like each click opens another prompt ontop of the first.
trent
Aug 06, 2012Are you using any type of event delegation? Do you event.preventDefault() or event.stopPropagation()? Could be triggering multiple prompts at once.
Chris
Aug 06, 2012Its ok Trent…I was being an idiot! I have it now; I needed to bind the jqplotClick to the chartdiv. Opening an closing nicely now!
Thanks for your help!
Chris
Chris
Aug 08, 2012Hey Trent, one more thing…is it possible to have no default button at all? So all that would be present is the X?
Thanks
C
trent
Aug 09, 2012Hey Chris, you sure can, just pass in buttons: {} and Impromptu will see that it is empty and not show the buttons.
Chris
Aug 09, 2012Thanks Trent!
Chris
Aug 16, 2012Hey Trent, one more :)
So if I pass an HTML string into the buttons option I seem to lose the value of v…is there a way around that?
buttons: [{title: ""+i18n.ecp.fk.modify+"",value:0},
{title: ""+i18n.ecp.fk.discontinue+"",value:1},
{title: ""+i18n.ecp.fk.pause+"",value:2},
{title: ""+i18n.ecp.fk.resume+"",value:3},
{title: ""+i18n.ecp.fk.close+"",value:-1}],
Chris
Aug 16, 2012Sorry Trent, that did not come out right…if you email me I will send the code back to you!
Thanks
C
Luis
Aug 27, 2012Hello thanks for the plugin firt of all. Now I am getting a JQuery not defined error in Firebug, but when looking at Net window in Firebug show no problem loading JQuery… any thoughts on this?
trent
Aug 28, 2012Sounds like you may be calling a jquery method before it is loaded. I would check 2 things. Use
$(document).ready(function(){$.prompt('test prompt');
});
and be sure that jquery is included before impromptu is included
Trisha
Nov 02, 2012I’m having an issue with another script (infieldlabel.js) not working while I’m using your Impromptu plugin. I’m using Impromptu as a confirm box after a form is submitted.
If you could please help me that would be nice.
Trisha
Nov 02, 2012Sorry for another post, just thought i’d let you know you can see the issue at the website provided.. mcgehee.ace-onecomputers.com/test
trent
Nov 03, 2012Hey Trisha, I visited the site and looks like impromptu is working. When I click submit it appears, and if I click Yes the form submits, and if I click No it doesn’t. Also looks like the labels are inside the field, I guess that is what was intended?
Wojtek Zeglin
Nov 26, 2012Trent, thanks a million for creating this plugin.. saved me hours of programming. Awesome job! :)