Flex: Linebreak problem with spark.components.TextArea inside a MXDataGridItemRenderer
Posted
by
radgar
on Stack Overflow
See other posts from Stack Overflow
or by radgar
Published on 2011-01-08T15:05:52Z
Indexed on
2011/01/08
15:53 UTC
Read the original article
Hit count: 301
Hi, I have a DataGrid
that has a MXDataGridItemRenderer
applied as an itemEditor
to one of the columns. The editor includes a spark.components.TextArea
control.
By default, any text item editor of a datagrid closes itself when [enter] key is pressed.. Keeping this in mind; What I want to do is:
- Prevent editor from closing on [SHIFT+ENTER] key but accept the linebreak (I can do this, see code below)
- Close the editor on [ENTER] key but do not accept the linebreak (could not achieve this)
Here is the current code in the MXDataGridItemRenderer
:
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true"
>
<fx:Script>
<![CDATA[
protected function onTxtDataKeyDown(event:KeyboardEvent):void
{
//Prevent editor from closing on [SHIFT+ENTER] key but accept the linebreak // » this works
if (event.shiftKey && event.keyCode == 13) { event.stopImmediatePropagation(); }
//Close the editor on [ENTER] key but do not accept the linebreak
else if (event.keyCode == 13) { event.preventDefault(); } // » does not work
}
]]>
</fx:Script>
<s:TextArea id="txtData" paddingTop="3" lineBreak="explicit"
text="{dataGridListData.label}"
verticalScrollPolicy="auto" horizontalScrollPolicy="off"
keyDown="onTxtDataKeyDown(event)"
/>
I also tried the textInput
event but that did not do the trick.
So: How can I prevent the linebreak when the editor is closed on [enter] key?
Any help is appreciated. Thanks.
EDIT: If I change the spark.components.TextArea to mx.controls.TextArea, second part with event.preventDefault()
will work as expected but then the first part where SHIFT+ENTER accepts the linebreak will not work.
© Stack Overflow or respective owner