Reputation: 33634
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:
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
{
if (event.keyCode == 13)
{
if (event.shiftKey)
{
//Prevent editor from closing on [SHIFT+ENTER] key but accept the linebreak
event.stopImmediatePropagation(); // » works
}
else
{
//Close the editor on [ENTER] key but do not accept the linebreak
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.
Upvotes: 0
Views: 2196
Reputation: 1
I'm not good English. Please see code.
<!--snip-->
<fx:Script>
<![CDATA[
protected function textArea_creationCompleteHandler(event:FlexEvent):void{
textArea.addEventListener(TextOperationEvent.CHANGING,onChangingHandler);
}
//This event is faster than KEY_DOWN.
private function onChangingHandler(event:TextOperationEvent):void {
if(event.operation is SplitParagraphOperation){
//SplitParagraphOperation only cancel.
event.preventDefault();
}
}
]]>
</fx:Script>
<s:TextArea id="textArea"
width="100"
creationComplete="textArea_creationCompleteHandler(event)"
height="60"
/>
<!--snip-->
Upvotes: 0
Reputation: 10232
According to the API reference keyDown
is cancellable only in AIR and not in Flash Player. Which one are you developing for? I was not able to cancel either keyDown
or textinput
in AIR. Could be a bug. Why don't you log a defect with Adobe and see what they say?
Update: I have confirmed that this is indeed a bug in spark.components.TextArea
. The thread http://forums.adobe.com/thread/703195 talks about similar issue.A bug has been logged against Flex as well - http://bugs.adobe.com/jira/browse/SDK-25542.
Workaround is to use mx.controls.TextArea
.
Upvotes: 1