You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Jason Guild <ja...@alaska.gov> on 2013/12/23 19:12:20 UTC

composite components and focus delegation

Hi all:

I have a reusable component that consists of many TextInputs that make 
up a mailing address form. When I use this component inside of a popup 
dialog I want to give focus to the first focusable component within the 
address form.

What is the best way to do this in the dialog so that I don't have to 
hardcode setFocus() on any of the particular fields within the address 
form? Does the address form component implement IFocusManagerComponent? 
If so, what is the recommended way of delegating focus within the 
address form
component? Do I override UIComponent.focusInHandler() in the composite 
component and call setFocus() on one of the child TextInputs?

Ideally, in my dialog I would simply call addrForm.setFocus() when it is 
shown and the address form would decide which of the sub-components 
should receive the focus. Any help on gotchas or other details I need to 
account for are greatly appreciated.

Thanks,
Jason



Re: composite components and focus delegation

Posted by mark goldin <ma...@gmail.com>.
No, firstTab is an instance on an object that lives in your composite
component. First Name for example. When you implement your composite
component you could have the following code in the childrenCreated of your
implementation class:

override protected function childrenCreated():void
{
super.childrenCreated();
compositeComponent.firstTab = this.FirstName;
}


On Mon, Dec 23, 2013 at 12:42 PM, Jason Guild <ja...@alaska.gov>wrote:

> Mark:
>
> Thanks for the reply.
>
> In your example, if firstTab were a reference to a composite component
> instance, how would that component delegate the setFocus() call to one of
> the child TextInputs within itself?
>
> The dialog class has only a reference to the entire composite component,
> and the component in the dialog has no knowledge of whether it appears in a
> popup dialog or anywhere else.
>
> Jason
>
>
> On 12/23/2013 9:22 AM, mark goldin wrote:
>
>> In my base popup class I have the following code (simplified):
>> public firstTab:*;
>>
>> this.addEventListener(FlexEvent.CREATION_COMPLETE, registerFirstTab);
>>
>> private function registerFirstTab(event:FlexEvent):void
>> {
>>       firstTab.setFocus();
>>       this.removeEventListener(FlexEvent.CREATION_COMPLETE,
>> registerFirstTab);
>> }
>> Implementation is responsible to populate firstTab with an object it wants
>> to have a focus on.
>>
>>
>>
>>
>> On Mon, Dec 23, 2013 at 12:12 PM, Jason Guild <jason.guild@alaska.gov
>> >wrote:
>>
>>  Hi all:
>>>
>>> I have a reusable component that consists of many TextInputs that make up
>>> a mailing address form. When I use this component inside of a popup
>>> dialog
>>> I want to give focus to the first focusable component within the address
>>> form.
>>>
>>> What is the best way to do this in the dialog so that I don't have to
>>> hardcode setFocus() on any of the particular fields within the address
>>> form? Does the address form component implement IFocusManagerComponent?
>>> If
>>> so, what is the recommended way of delegating focus within the address
>>> form
>>> component? Do I override UIComponent.focusInHandler() in the composite
>>> component and call setFocus() on one of the child TextInputs?
>>>
>>> Ideally, in my dialog I would simply call addrForm.setFocus() when it is
>>> shown and the address form would decide which of the sub-components
>>> should
>>> receive the focus. Any help on gotchas or other details I need to account
>>> for are greatly appreciated.
>>>
>>> Thanks,
>>> Jason
>>>
>>>
>>>
>>>
>

Re: composite components and focus delegation

Posted by Alex Harui <ah...@adobe.com>.

On 12/23/13 10:42 AM, "Jason Guild" <ja...@alaska.gov> wrote:

>Mark:
>
>Thanks for the reply.
>
>In your example, if firstTab were a reference to a composite component
>instance, how would that component delegate the setFocus() call to one
>of the child TextInputs within itself?
The component would need some strategy to decide what should get focus
when the component's setFocus gets called.  It could be the first child,
or some other logic, maybe a property set some where.  DataGrid, for
example, puts focus on one of its renderers if it is editable.  IIRC,
Alert puts focus on the default button.
>
>The dialog class has only a reference to the entire composite component,
>and the component in the dialog has no knowledge of whether it appears
>in a popup dialog or anywhere else.
IMHO, it shouldn't need to know that.  It is up to the consumer of the
composite component to decide whether to call that component's setFocus()
or not.


Re: composite components and focus delegation

Posted by Jason Guild <ja...@alaska.gov>.
Mark:

Thanks for the reply.

In your example, if firstTab were a reference to a composite component 
instance, how would that component delegate the setFocus() call to one 
of the child TextInputs within itself?

The dialog class has only a reference to the entire composite component, 
and the component in the dialog has no knowledge of whether it appears 
in a popup dialog or anywhere else.

Jason

On 12/23/2013 9:22 AM, mark goldin wrote:
> In my base popup class I have the following code (simplified):
> public firstTab:*;
>
> this.addEventListener(FlexEvent.CREATION_COMPLETE, registerFirstTab);
>
> private function registerFirstTab(event:FlexEvent):void
> {
>       firstTab.setFocus();
>       this.removeEventListener(FlexEvent.CREATION_COMPLETE,
> registerFirstTab);
> }
> Implementation is responsible to populate firstTab with an object it wants
> to have a focus on.
>
>
>
>
> On Mon, Dec 23, 2013 at 12:12 PM, Jason Guild <ja...@alaska.gov>wrote:
>
>> Hi all:
>>
>> I have a reusable component that consists of many TextInputs that make up
>> a mailing address form. When I use this component inside of a popup dialog
>> I want to give focus to the first focusable component within the address
>> form.
>>
>> What is the best way to do this in the dialog so that I don't have to
>> hardcode setFocus() on any of the particular fields within the address
>> form? Does the address form component implement IFocusManagerComponent? If
>> so, what is the recommended way of delegating focus within the address form
>> component? Do I override UIComponent.focusInHandler() in the composite
>> component and call setFocus() on one of the child TextInputs?
>>
>> Ideally, in my dialog I would simply call addrForm.setFocus() when it is
>> shown and the address form would decide which of the sub-components should
>> receive the focus. Any help on gotchas or other details I need to account
>> for are greatly appreciated.
>>
>> Thanks,
>> Jason
>>
>>
>>


Re: composite components and focus delegation

Posted by mark goldin <ma...@gmail.com>.
In my base popup class I have the following code (simplified):
public firstTab:*;

this.addEventListener(FlexEvent.CREATION_COMPLETE, registerFirstTab);

private function registerFirstTab(event:FlexEvent):void
{
     firstTab.setFocus();
     this.removeEventListener(FlexEvent.CREATION_COMPLETE,
registerFirstTab);
}
Implementation is responsible to populate firstTab with an object it wants
to have a focus on.




On Mon, Dec 23, 2013 at 12:12 PM, Jason Guild <ja...@alaska.gov>wrote:

> Hi all:
>
> I have a reusable component that consists of many TextInputs that make up
> a mailing address form. When I use this component inside of a popup dialog
> I want to give focus to the first focusable component within the address
> form.
>
> What is the best way to do this in the dialog so that I don't have to
> hardcode setFocus() on any of the particular fields within the address
> form? Does the address form component implement IFocusManagerComponent? If
> so, what is the recommended way of delegating focus within the address form
> component? Do I override UIComponent.focusInHandler() in the composite
> component and call setFocus() on one of the child TextInputs?
>
> Ideally, in my dialog I would simply call addrForm.setFocus() when it is
> shown and the address form would decide which of the sub-components should
> receive the focus. Any help on gotchas or other details I need to account
> for are greatly appreciated.
>
> Thanks,
> Jason
>
>
>