Welcome!

ColdFusion Authors: Maureen O'Gara, Hovhannes Avoyan, Yakov Fain, Pat Romanski, Liz McMillan

Related Topics: ColdFusion

ColdFusion: Article

Make Your Flash Forms More FLEXible

Like what you can do with Flash Forms? Wish you could do more?

Notice though that rather than validate the input controls themselves I'm validating userdata. This is a data model that holds all the user data in one object, and it is this that's passed back to the parent window after saving.

<mx:Model id="userdata">
   <user>
     <name>{namefield.text}</name>
     <phone>{phonefield.text}</phone>
     <email>{emailfield.text}</email>
   </user>
</mx:Model>

This in turn is bound to the input controls, and as such is always "up-to-date." Validation is handled using the Flex validation controls:

<mx:StringValidator     field="userdata.user.name"/>
<mx:PhoneNumberValidator     field="userdata.user.phone"/>
<mx:EmailValidator     field="userdata.user.email"/>

This ensures that the user supplies required data and that the telephone number and e-mail address are correctly formatted. Assuming that the user supplies all the correct data then the save function eventually passes the data back to the parent window before closing itself. It does this by using the parentref that our main form passed when it opened the window and calls the public function that we created there to get the updated data.

parentref.setUserData(userdata.user);

The setUserData function in Demo5.mxml simply assigns the data objects passed to it to userObj, the object to which our Label fields are bound, so they immediately update with the newly saved values.

Now for a few "gotchas" that you'd might like to watch out for. The first is the pop-up window's close button. You'll notice in the code that I disable the entire TitleWindow control when I'm saving to prevent the user from making any further changes or pressing submit a second time. That works great, but the close button is always active. Function closePopup checks the window's enabled status prior to closing.

In this example the window closes just fine. However, there's a well-known Flex bug whereby, if you close a pop-up window with a drop shadow in the response handler of a remoting call then the window is removed but the drop shadow remains behind (see Figure 7).

One solution is simply to use styles to disable the default drop shadow. If, however, you'd like to use the drop shadow then these two lines of code will sort the problem out for you:

    windowObject.setStyle("dropShadow",false);
    windowObject.redraw(true);

The first simply removes the drop shadow. We do this before closing the window. The second is needed because of the way flash does its redraws. Without it you'll find that the window is closed before the drop shadow is removed. The code forces an immediate redraw. See Listing 8 for an example that uses remoting. Simply comment out those two lines to see the shadow bug in action. Listing 9 is a very simple CFC that handles the saveUser function.

Finally, few other things to note:

  • In userEditForm.mxml (Listings 7/8), you'll notice the <mx:TitleWindow> tag has a modalTransparency attribute that I've set to "75." This makes everything behind the pop-up window 75% transparent. This looks great and is a clear indicator to the user that the remaining application is disabled while the pop-up is open. See Figure 5.
  • You can center your pop-up by adding this.centerPopUp() to your load attribute.

More Stories By Ian Bale

Ian Bale is co-director of Celtic Internet ltd. (www.celticinternet.com), a UK-based software engineering and consultancy company. Ian has worked as a consultant since 1989 in both the telecom and Internet industries.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Pim 11/21/06 06:53:17 PM EST

I was wondering one thing, when you use flash forms and submit data to another cfm page, values are accessible as if they were normal forms (form.firstname, form.address ...), what happens in this case ? Would you have to use remoting to submit them ?
Regards,
Pim

Fritz Dimmel 11/21/06 09:19:26 AM EST

Hi!
This article is really, really great! The possiblity of using MXML files in flash forms is unbelievable!
Why didn't you write this article one year earlier? :-) We could have used it really!

Thanks,
Fritz