Flex ItemRenator禁止在文本输入之间使用制表符

u3r8eeie  于 2022-09-21  发布在  Apache
关注(0)|答案(9)|浏览(140)

我有一个自定义的项目呈现器,它在3个面板中的每个面板中显示5个文本输入:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:VBox
  3. xmlns:mx="http://www.adobe.com/2006/mxml"
  4. height="300"
  5. width="800"
  6. creationComplete="onCreationComplete()"
  7. >
  8. <!-- code-behind -->
  9. <mx:Script source="ChainListRenderer.mxml.as" />
  10. <mx:Label text="{data.title}" fontSize="25" fontWeight="bold" width="100%" textAlign="center" />
  11. <mx:HBox>
  12. <mx:Panel id="triggerPanel" title="Trigger" width="260">
  13. <mx:VBox id="tpBoxes" width="100%" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
  14. <mx:TextInput id="trigger1" width="100%" textAlign="left" tabIndex="0" tabEnabled="true" />
  15. <mx:TextInput id="trigger2" width="100%" textAlign="left" tabIndex="1" tabEnabled="true" />
  16. <mx:TextInput id="trigger3" width="100%" textAlign="left" tabIndex="2" tabEnabled="true" />
  17. <mx:TextInput id="trigger4" width="100%" textAlign="left" tabIndex="3" tabEnabled="true" />
  18. <mx:TextInput id="trigger5" width="100%" textAlign="left" tabIndex="4" tabEnabled="true" />
  19. </mx:VBox>
  20. </mx:Panel>
  21. <mx:Panel id="linkPanel" title="Link" width="260">
  22. <mx:VBox id="lpBoxes" width="100%" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
  23. <mx:TextInput id="link1" width="100%" textAlign="left" tabIndex="5" tabEnabled="true" />
  24. <mx:TextInput id="link2" width="100%" textAlign="left" tabIndex="6" tabEnabled="true" />
  25. <mx:TextInput id="link3" width="100%" textAlign="left" tabIndex="7" tabEnabled="true" />
  26. <mx:TextInput id="link4" width="100%" textAlign="left" tabIndex="8" tabEnabled="true" />
  27. <mx:TextInput id="link5" width="100%" textAlign="left" tabIndex="9" tabEnabled="true" />
  28. </mx:VBox>
  29. </mx:Panel>
  30. <mx:Panel id="answerPanel" title="Answer" width="260">
  31. <mx:VBox id="apBoxes" width="100%" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
  32. <mx:TextInput id="answer1" width="100%" textAlign="left" tabIndex="10" tabEnabled="true" />
  33. <mx:TextInput id="answer2" width="100%" textAlign="left" tabIndex="11" tabEnabled="true" />
  34. <mx:TextInput id="answer3" width="100%" textAlign="left" tabIndex="12" tabEnabled="true" />
  35. <mx:TextInput id="answer4" width="100%" textAlign="left" tabIndex="13" tabEnabled="true" />
  36. <mx:TextInput id="answer5" width="100%" textAlign="left" tabIndex="14" tabEnabled="true" />
  37. </mx:VBox>
  38. </mx:Panel>
  39. </mx:HBox>
  40. </mx:VBox>

不幸的是,当用作ItemReneller时,文本输入之间的Tab键不起作用,即使使用上面的tabIndex值也是如此。如果我将这段代码复制到它自己的MXML应用程序中,文本输入之间的跳转就会正常工作。

有谁知道在这种情况下如何恢复跳转?如果我不得不在没有这么简单的可用性元素的情况下发布这款应用程序,那将是一种耻辱。

我想我可能需要实现mx.managers.IFocusManagerComponent,但我找不到任何关于如何做到这一点的例子,而FocusManager docs也没有帮助。

hkmswyz6

hkmswyz61#

我使用mx:vbox作为定制的itemRender,并为我的数据网格设置rendererIsEditor=“true”,而且我还遇到了Tab键顺序的问题。

我得出的结论是,itemRender需要实现IFocusManagerComponent,以便主应用程序的FocusManager()能够正确地跳转到它。我尝试实现该接口:

  1. <?xml version="1.0"?>
  2. <mx:VBox implements="mx.managers.IFocusManagerComponent" ...>
  3. [the rest of my itemRenderer code]
  4. </mx:VBox>

...结果是做起来相当复杂...要实现很多接口函数。

然而,在我的例子中,我很幸运;我的itemRenender中只有一个TextInput元素(其余的都是定制代码、验证器和格式化程序),所以我将itemRender从mx:vbox转换为mx:TextInput(它已经实现了IFocusManager组件):

  1. <?xml version="1.0"?>
  2. <mx:TextInput ...>
  3. [the rest of my itemRenderer code]
  4. </mx:TextInput>

瞧啊!我的Tab键顺序问题已修复。

我想对于那些使用更复杂的itemRenderers的人来说,结论是您需要在类中完全实现IFocusManagerComponent接口...这可能很好,因为它看起来将告诉Flex如何通过您的itemRenderer域定制制表符。或者,您可以将顶级标记更改为已经实现该接口的内容,例如:您是否可以将mx:vbox嵌套在如下内容中:

  1. <mx:Container focusIn="FocusManager.setFocus(trigger1)">

...也许能让它起作用?代码比我复杂的人应该试一试,看看会发生什么。

展开查看全部
v09wglhw

v09wglhw2#

我在“ListBase派生”组件中使用的itemRender遇到了同样的问题。我发现所有“ListBase派生的”组件都将所有项呈现器 Package 在一个ListBaseContent Holder中。

从ListBase源:

  1. /**
  2. * An internal display object that parents all of the item renderers,
  3. * selection and highlighting indicators and other supporting graphics.
  4. * This is roughly equivalent to the <code>contentPane</code> in the
  5. * Container class, and is used for managing scrolling.
  6. */
  7. protected var listContent:ListBaseContentHolder;

默认情况下,此类的tabChildrentabEnabled属性设置为FALSE。我能找到的唯一解决办法是创建一个从列表派生的MyList组件,并以这种方式覆盖createChildren方法(其中的listContent被初始化):

  1. import flash.display.DisplayObject;
  2. import mx.controls.List;
  3. public class MyList extends List {
  4. override protected function createChildren():void {
  5. super.createChildren();
  6. this.listContent.tabChildren = this.tabChildren
  7. this.listContent.tabEnabled = this.tabEnabled
  8. }
  9. }

然后使用“”而不是“<mx:list/>”组件将ItemRender中的制表符功能带回给我。

希望能有所帮助,

展开查看全部
vx6bjr1n

vx6bjr1n3#

我认为我可能正在朝着正确的方向前进,但我还没有完全做到这一点。

我有我的主应用程序,其中HorizontalList使用了一个定制的ItemRender:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application
  3. xmlns:mx="http://www.adobe.com/2006/mxml"
  4. xmlns:com="ventures.view.component.*"
  5. layout="absolute"
  6. backgroundColor="#ffffff"
  7. preinitialize="onPreInitialize()"
  8. click="onClick(event)"
  9. >
  10. <!-- code-behind -->
  11. <mx:Script source="ConsumptionChain.as" />
  12. <!-- show chain links -->
  13. <mx:HorizontalList
  14. id="ChainList"
  15. direction="horizontal"
  16. dataProvider="{chainData}"
  17. rollOverColor="#ffffff"
  18. selectionColor="#ffffff"
  19. horizontalScrollPolicy="off"
  20. left="20"
  21. right="20"
  22. top="20"
  23. height="300"
  24. minWidth="802"
  25. rowHeight="300"
  26. columnWidth="800"
  27. tabChildren="false"
  28. itemRenderer="ventures.view.ItemRenderer.ChainListRenderer"
  29. />
  30. </mx:Application>

我已经更新了原始问题中的代码示例,以包含整个ItemReneller MXML(适用部分);下面是ActionScript代码隐藏:

  1. /*
  2. * ChainListRenderer.mxml.as -- code-behind for ChainListRenderer.mxml
  3. */
  4. import flash.events.Event;
  5. import flash.events.KeyboardEvent;
  6. import flash.ui.Keyboard;
  7. //used to combine all textboxes in a single array to make looping through them with the TAB key easier
  8. private var allBoxes:Array;
  9. public function expandPanel(e:Event):void {
  10. trace(e.currentTarget);
  11. var state : String = e.currentTarget.parent.parent.id;
  12. if (state != this.currentState)
  13. this.currentState = state;
  14. }
  15. private function onCreationComplete():void{
  16. //this function will be run on each object via the map function
  17. function forEach(o:Object, index:int, ar:Array):void{
  18. o.addEventListener(FocusEvent.FOCUS_IN, expandPanel)
  19. o.addEventListener(MouseEvent.CLICK, stopBubble); //don't propagate click events (which return to base state)
  20. o.addEventListener(KeyboardEvent.KEY_DOWN, customTabbing); //fix tabbing between text fields
  21. }
  22. this.addEventListener(KeyboardEvent.KEY_DOWN, customTabbing);
  23. //loop over textboxes and add the focusIn event listener
  24. tpBoxes.getChildren().map(forEach);
  25. lpBoxes.getChildren().map(forEach);
  26. apBoxes.getChildren().map(forEach);
  27. //create an "allBoxes" array that is used by the customTabbing function
  28. allBoxes = tpBoxes.getChildren();
  29. function forEachTabbing(o:Object, index:int, ar:Array):void {
  30. allBoxes.splice(allBoxes.length, 0, o);
  31. }
  32. lpBoxes.getChildren().map(forEachTabbing);
  33. apBoxes.getChildren().map(forEachTabbing);
  34. }
  35. //this function is used to prevent event bubbling
  36. private function stopBubble(e:Event):void {
  37. e.stopPropagation();
  38. }
  39. //this function re-implements tabbing between text fields, which is broken when inside an itemRenderer
  40. public function customTabbing(e:KeyboardEvent):void {
  41. trace('keyCode: ' && e.keyCode.toString());
  42. if (e.keyCode == flash.ui.Keyboard.TAB){
  43. trace(focusManager.getFocus());
  44. //loop over array of all text-boxes
  45. for (var i:int = 0; i < allBoxes.length; i++){
  46. trace(i.toString());
  47. //if event (keypress) current target is the current TextInput from the array
  48. if (e.currentTarget == allBoxes[i]){
  49. //then focus the NEXT TextInput, and wrap if at last one
  50. allBoxes[((i+1) % allBoxes.length)].setFocus();
  51. //break out of the loop
  52. break;
  53. }
  54. }
  55. //prevent arrow keys from navigating the horizontal list
  56. e.stopPropagation();
  57. }
  58. }

本质上,我在这里尝试做的是通过在每个文本字段的KEY_DOWN事件上检查TAB键来重新实现跳转,并使用它将焦点移动到下一个TextInput(从最后一个换行到第一个TextInput)。但这并没有达到预期的效果,焦点仍然跳到此HorizontalList之外的下一个控件。

你知道接下来该怎么做吗?

展开查看全部
ghg1uchk

ghg1uchk4#

您为什么要做tabChildren=“False”?您不想给Horzion List的子项添加标签吗?由于项目呈现器是列表的子级...

qij5mzcb

qij5mzcb5#

用我使用的方法,这似乎是不可能的。我没有使用带有定制条目呈现器的列表,而是切换到单个条目视图组件和单独的列表来显示所有条目的摘要,这让我修复了我的问题。

czfnxgou

czfnxgou6#

我也遇到了同样的问题,通过尝试重新实现选项卡按钮的行为来解决它。成功的秘诀就是简单地使用event.preventdefault()方法。使用的代码显示在前面。

  1. private function initFocusMap():void {
  2. focusMap = {
  3. InNom:benefPersona.InApePat,
  4. InApePat:benefPersona.InApeMat,
  5. InApeMat:benefPersona.InFecNacimiento,
  6. InFecNacimiento:benefPersona.InRFC,
  7. InRFC:benefPersona.InCURP,
  8. InCURP:benefPersona.InIdSexo,
  9. InIdSexo:benefPersona.InIdParentesco,
  10. InIdParentesco:benefPersona.InPorc,
  11. InPorc:domBeneficiario.InCalle,
  12. InCalle:domBeneficiario.InNumExterior,
  13. InNumExterior:domBeneficiario.InNumInterior,
  14. InNumInterior:domBeneficiario.InCP,
  15. InCP:domBeneficiario.InColonia,
  16. InColonia:domBeneficiario.InIdPais,
  17. InIdPais:domBeneficiario.InIdEdo,
  18. InIdEdo:domBeneficiario.InIdCiudad,
  19. InIdCiudad:benefPersona.InNom
  20. }
  21. }
  22. private function kfcHandler(event:FocusEvent):void {
  23. var id:String = ""
  24. if (event.target is AperClsDateField || event.target is AperClsCombo) {
  25. id = event.target.id;
  26. } else {
  27. id = event.target.parent.id;
  28. }
  29. if (id != "InIdDelegacionMunic") {
  30. event.preventDefault();
  31. focusManager.setFocus(focusMap[id]);
  32. }
  33. }
展开查看全部
nhn9ugyo

nhn9ugyo7#

我在我的AdvancedDataGrid中遇到了同样的问题(顺便说一句,我正在使用Flex SDK 3.5),但这篇文章对我制作标签友好的itemReneller非常有帮助,所以我也想做点贡献:)

要实现这一点,您还需要更改网格和gridColumn的一些属性。

让我们先来谈谈网格和网格列。

大家都知道,当您将网格的“edable”属性设置为“true”时,您可以在每个列单元格之间使用Tab键(假设没有将列的“edable”属性设置为“False”)。

第1步,将网格的“可编辑”属性设置为“真”

步骤2,使网格的“可编辑”属性也设置为“True”,并将“rendererIsEditor”设置为“True”

将datafield设置为伪字段很重要,因为我们将呈现器设置为编辑器,这意味着您在itemRenator中更新的任何内容都将分配给datafield,即,您将datafield设置为“foo”,其类型为int,并且您有非基元对象填充comboBox itemRender。当您进行选择时,该对象将被分配给“foo”

步骤3,将网格的列“datafield”属性也设置为伪字段。

现在,让我们来做一些事情,使Tab键能够在itemReneller上工作

我知道这不是一个优化的版本,但这将适用于第一次通过。

  1. import mx.core.mx_internal;
  2. import mx.managers.IFocusManagerComponent;
  3. use namespace mx_internal;
  4. public class FriendlyItemRendererContainer extends HBox implements IFocusManagerComponent
  5. {
  6. public function FriendlyItemRendererContainer ()
  7. {
  8. super();
  9. addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler);
  10. }
  11. private var _listData:DataGridListData;
  12. //This is required to make it work as itemEditor
  13. public var text:String;
  14. private function keyFocusChangeHandler(event:FocusEvent):void
  15. {
  16. if (event.keyCode == Keyboard.TAB &&
  17. ! event.isDefaultPrevented() &&
  18. findNextChildToFocus(event.shiftKey))
  19. {
  20. event.preventDefault();
  21. }
  22. }
  23. private function findNextChildToFocus(shiftKey:Boolean):Boolean
  24. {
  25. var myChildrenAry:Array = getChildren();
  26. var incr:int = shiftKey ? -1 : 1;
  27. var index:int = shiftKey ? myChildrenAry.length : 0;
  28. var focusChildIndex:int = 0;
  29. var found:Boolean = false;
  30. for (focusChildIndex = 0; focusChildIndex < myChildrenAry.length; ++focusChildIndex)
  31. {
  32. if (!(myChildrenAry[focusChildIndex] as UIComponent).visible ||
  33. (myChildrenAry[focusChildIndex] is Container))
  34. {
  35. //If it's an invisible UIComponent or a container then just continue
  36. continue;
  37. }
  38. if (myChildrenAry[focusChildIndex] is TextInput)
  39. {
  40. if (systemManager.stage.focus == (myChildrenAry[focusChildIndex] as TextInput).getTextField())
  41. {
  42. (myChildrenAry[focusChildIndex] as UIComponent).drawFocus(false);
  43. found = true;
  44. break;
  45. }
  46. }
  47. else
  48. {
  49. if (systemManager.stage.focus == myChildrenAry[focusChildIndex])
  50. {
  51. (myChildrenAry[focusChildIndex] as UIComponent).drawFocus(false);
  52. found = true;
  53. break;
  54. }
  55. }
  56. }
  57. if (!found)
  58. {
  59. focusChildIndex = 0;
  60. }
  61. while (true)
  62. {
  63. focusChildIndex = focusChildIndex + incr;
  64. if ((focusChildIndex < 0) || (focusChildIndex >= myChildrenAry.length))
  65. {
  66. UIComponentGlobals.nextFocusObject = null;
  67. return false;
  68. }
  69. else
  70. if (myChildrenAry[focusChildIndex] is UIComponent)
  71. {
  72. (myChildrenAry[focusChildIndex] as UIComponent).setFocus();
  73. (myChildrenAry[focusChildIndex] as UIComponent).drawFocus(true);
  74. break;
  75. }
  76. }
  77. return true;
  78. }
  79. override public function setFocus():void
  80. {
  81. var myChildrenAry:Array = getChildren();
  82. if (myChildrenAry.length > 0)
  83. {
  84. for (var i:int = 0; i < myChildrenAry.length; ++i)
  85. {
  86. if ((myChildrenAry[i] is UIComponent) && (myChildrenAry[i] as UIComponent).visible)
  87. {
  88. (myChildrenAry[i] as UIComponent).setFocus();
  89. (myChildrenAry[i] as UIComponent).drawFocus(true);
  90. break;
  91. }
  92. }
  93. }
  94. }
  95. public function get listData():BaseListData
  96. {
  97. return _listData;
  98. }
  99. public function set listData(value:BaseListData):void
  100. {
  101. _listData = DataGridListData(value);
  102. }
  103. }

关于如何在您的itemReneller上使用它的示例:

  1. <FriendlyItemRendererContainer xmlns:mx="http://www.adobe.com/2006/mxml">
  2. <mx:TextInput/>
  3. <mx:Button label="Boo"/>
  4. <mx:RadioButton/>
  5. <<mx:TextInput/>
  6. <mx:Button label="Baa"/>
  7. </FriendlyItemRendererContainer>

然后只需将其放入网格列中,就是这样。

好好享受吧。

展开查看全部
cunj1qz1

cunj1qz18#

基本上,您希望删除焦点更改事件的默认行为。我认为你需要这样做:

  1. 1. yourRenderer.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, onKeyFocusChange);
  2. 2. since you want to stop tab key, in the handler, do this:
  3. if (event.keyCode == Keyboard.TAB)
  4. event.preventDefault()
  5. 3. in your keyDown handler, catch TAB, then you can manually move your focus.

相关问题