I'm using alert()
to output my validation errors back to the user as my design does not make provision for anything else, but I would rather use jQuery UI dialog as the alert dialog box for my message.
Since errors are not contained in a (html) div, I am not sure how to go about doing this. Normally you would assign the dialog()
to a div say $("#divName").dialog()
but I more need a js function something like alert_dialog("Custom message here")
or something similiar.
Any ideas?
DAlert jQuery UI Plugin Check this out, This may help you
Using some of the info in here I ended up creating my own function to use.
Could be used as...
jQuery UI Alert Replacement
As mentioned by nux and micheg79 a node is left behind in the DOM after the dialog closes.
This can also be cleaned up simply by adding:
to the close method of the dialog. Example adding this line to eidylon's answer:
EDIT: I had problems getting callback function to run and found that I had to add parentheses () to onCloseCallback to actually trigger the callback. This helped me understand why: In JavaScript, does it make a difference if I call a function with parentheses?
I don't think you even need to attach it to the DOM, this seems to work for me:
Here's a JS fiddle:
http://jsfiddle.net/TpTNL/98
Building on eidylon's answer, here's a version that will not show the title bar if TitleMsg is empty:
see jsfiddle
I took @EkoJR's answer, and added an additional parameter to pass in with a callback function to occur when the user closes the dialog.
You can then call it and pass it a function, that will occur when the user closes the dialog, as so: