Saturday, March 03, 2007

Is Flex's valueCommit dispatched at the right time?

The more I work with validators, the more concerned I am about whether TextInput's valueCommit event is raised at the right time. You could imagine a scenario where a TextInput's text property is only committed when the user is happy with the input and moves focus to another component, at which point the valueCommit event is dispatched. Unfortunately that's not how the TextInput component works. In fact, the TextInput component updates it's text property (and anything bound to its text property) after each key depression. Hence its actually "committing" its "value" after each key depression (when the change event is dispatched). This makes no sense to me at all. Either the valueCommit event is badly named or its dispatched at the wrong time in the live cycle of this component. Thoughts?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="white" backgroundImage="">
<mx:Script>
<![CDATA[
private function onChange() : void
{
trace( this.textInput.text ) ;
}

private function onValueCommit() : void
{
trace( "onValueCommit()" ) ;
}
]]>
</mx:Script>
<mx:Label text="{this.textInput.text}" />
<mx:TextInput id="textInput" change="this.onChange()" valueCommit="this.onValueCommit()" />
<mx:TextInput />
</mx:Application>

3 comments:

Anonymous said...

great

Anonymous said...

valueCommit seems to be the neglected step-child event. It doesn't fire consistently across controls and when you write list item editors, it doesn't fire until after itemEndEdit, which makes it very tedious to use in a grid or list except for the simplest cases.

Flex seems to encourage real-time updating as the user types - even though you rarely want that in a typical business application.

Monster Bet said...

Couldn't agree more, it doesn't operate the same when under cross browser testing.