Ext Message Box in ColdFusion

Word Count: 743

Going forward with the new project I thought I would look at some new functionality. One reader already asked me about the message box class in Ext. I started writing some code tonight and I wanted to get some feedback on this as well. Before we look at some code we need to think about why we use the different message boxes. Ext comes with the following types of message boxes.

  • Alert - Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt)
  • Confirm - Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm).
  • Prompt - Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
  • Progress - Displays a message box with a progress bar. This message box has no buttons and is not closeable by the user.

As you can see these types of message boxes are comparable to JavaScript dialog boxes. So we would probably use them in the same scenarios. An alert box is great for notifying a user that some action took place, a confirm dialog would be good to ask a user for confirmation and a prompt is great for collecting data. If anyone has more specific use cases I would like to know so I can work up some examples for what you might use the message boxes for.

Time to check out some code. So sticking with the same theme as cf_window we need to make it easy to create and use. The first thing I did was make it so that all of the message boxes are created in the same manner. To tell them what type of box they are we just pass a type attribute. Valid types would be alert,confirm,prompt and progress. The example below would create a basic alert box and could then be made visible using the id as the function call.

<cfimport prefix="ext" taglib="lib">
<html>
<head>
   <title>Ext Message Box / Basic Alert</title>
   <ext:include widget="messagebox" adapter="ext"/>
</head>

<body>

   <ext:msg id="showAlert" type="alert" title="Status">
   Changes saved successfully.
   </ext:msg>

   <a href="##" onclick="showAlert();">Show Alert Box</a>

   
</body>
</html>

In a bit more advanced message box we could assign a handler function. In the case of our alert box we want to know if the user clicked ok or closed the message box using the close button. To accomplish this we assign our handler using the handler attribute and pass the btn to our handler method.

<cfimport prefix="ext" taglib="lib">
<html>
<head>
   <title>Ext Message Box / Basic Alert</title>
   <ext:include widget="messagebox" adapter="ext"/>
   <script type="text/javascript">
   function myHandler(btn) {
      if(btn=='ok') {
         // do something          alert("ok");
      } else {
         // user closed box          alert("closed");
      }
   }
   </script>
</head>

<body>

   <ext:msg id="showAlert" type="alert" title="Status" handler="myHandler">
   Changes saved successfully.
   </ext:msg>

   <a href="##" onclick="showAlert();">Show Alert Box</a>

</body>
</html>
At this point I have no real examples to show you but I should shortly. I think this is a great start on the message box class though and would love to hear what you think. Is this something you would use? Does the implementation make sense? If I get caught up on work by the weekend I might finish this with a ton of examples just like the window has. I have a new project setup for all of this, just not ready to announce it until I get it going.

Comments

#1 Posted By: dave Posted On: 1/16/08 12:45 AM
i love you dan!! haha

Soon as I can check this out i will visit your wishlist :)

thanks
#2 Posted By: Chris Dawes Posted On: 1/16/08 2:02 AM
Check out the docs... customisation is at your fingertips:

ie:

Ext.Msg.show({
title:'Save Changes?',
msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
buttons: Ext.Msg.YESNOCANCEL,
fn: processResult,
animEl: 'elId',
icon: Ext.MessageBox.QUESTION
});
#3 Posted By: Dan Vega Posted On: 1/16/08 8:05 AM |
Author Comment
@Dave - Thank you!

@Chris - I saw that and already started messing around with adding custom as a new type!
#4 Posted By: Shaun Posted On: 1/17/08 3:59 PM
Hey Dan,

check your href to ben forta's blog fort*a*.com

sorry to post here couldn't find a contact method for you.
#5 Posted By: Dan Vega Posted On: 1/17/08 4:03 PM |
Author Comment
Thanks Shaun - You can email me at danvega at gmail dot com. I really do need to update my about page and add a contact page.
#6 Posted By: dave Posted On: 1/21/08 1:31 AM
how is this one coming along?
#7 Posted By: Kevin Roche Posted On: 1/21/08 4:34 AM
Dan,

This is great work. I have several clients who are still on older versions of CF and being able to easily use the EXT libraries with them is wonderful.

Are you planning on doing somthing with the datepicker? For me that would be a big bonus. I must admit I find the Ext way of doing things a bit obscure and have struggled to use the new date picker. I have created a custom tag that uses it but I am not happy with it right now.
#8 Posted By: Dan Vega Posted On: 1/21/08 9:15 AM |
Author Comment
@Dave - It is built in to my new cfExt project. I will make an announcement on this shortly.

@Kevin - Thanks for the comments! I could easily work in the date picker. I am curious though, would you need it for it just simple forms or would there be another use?
#9 Posted By: Kevin Roche Posted On: 1/21/08 9:19 AM
I only really need it for simple forms but I like the ability to set the locale so that it does whatever language you want.
#10 Posted By: muhammed Posted On: 2/13/08 1:49 PM
i want love message and friends message
#11 Posted By: Obamy Posted On: 6/17/09 3:38 PM
@muhammed

Spend some time in prison. You'll make lots of friends and get many love messages.


Post Your Comment

Leave this field empty







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.