PDA

View Full Version : [OPEN] [#310] Window.DefaultFocus problem



michaeld
Jul 31, 2013, 9:38 AM
Could you explain how DefaultFocus is supposed to work? Documentation says ("The id of a button to focus when this window received the focus.")

This isn't working for me. See example.

Also, what is AutoFocus="true" supposed to do and how is it different?



<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
}
</script>


<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Test</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Viewport ID="vp" runat="server" Layout="VBoxLayout">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>


<ext:Window ID="Panel1" runat="server" Border="false" BodyBorder="0" BodyCls="BodyFrame" Layout="HBoxLayout" DefaultFocus="STitleE" Width="200">
<LayoutConfig>
<ext:HBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>


<ext:Container runat="server" Flex="1">
<Items>
<ext:Panel ID="Panel2" runat="server" Border="false" BodyBorder="0" MarginSpec="0 2px" Height="100" Frame="true">
<Items>
<ext:Label runat="server" Html="Test" Height="100" />
<ext:TextField ID="STitleE" runat="server" MaxLengthText="12" MaxLength="12" Width="94" EnforceMaxLength="true"
MinLength="2" AllowBlank="false" CausesValidation="true" AutoFocus="true" />
</Items>
</ext:Panel>

</Items>
</ext:Container>

</Items>
</ext:Window>


</Items>
</ext:Viewport>

</form>
</body>
</html>

Daniil
Jul 31, 2013, 1:39 PM
Hi @michaeld,

As for the DefaultFocus it is a bug.
http://www.sencha.com/forum/showthread.php?266701

Please see the last post where I propose possible solutions.

Created an Issue to track it.
https://github.com/extnet/Ext.NET/issues/310

As for the AutoFocus option.

The difference from the DefaultFocus is: it should be set up for a focused Component, not for its Container.

However, it appears to be broken as well. Fixed in SVN.

Thank you for the report!

michaeld
Aug 02, 2013, 3:54 AM
As for the DefaultFocus it is a bug.
http://www.sencha.com/forum/showthread.php?266701
Please see the last post where I propose possible solutions.


I noticed the solutions you added, but how come you didn't add your suggestion to ext.net trunk as an override? It seems to me that you often do so until such time as it's addressed in extjs? It could be an undetermined amount of time till 4.3 after all.



As for the AutoFocus option.
The difference from the DefaultFocus is: it should be set up for a focused Component, not for its Container.
However, it appears to be broken as well. Fixed in SVN.
Thank you for the report!

Still a little confused how AutoFocus="true" works. Do I set this to a single control in a form for the control that I want to have focus set to when the window shows or renders? That is, all other controls are set to AutoFocus="false", the default? What happens if 2 controls have AutoFocus="true"

Not sure I understand the mechanism yet.

Daniil
Aug 02, 2013, 6:04 AM
I noticed the solutions you added, but how come you didn't add your suggestion to ext.net trunk as an override? It seems to me that you often do so until such time as it's addressed in extjs? It could be an undetermined amount of time till 4.3 after all.


Yes, it is a common practice but depends on circumstances. In this case everything looks good to commit it to SVN. So, done. Thank you again for the report.



Still a little confused how AutoFocus="true" works. Do I set this to a single control in a form for the control that I want to have focus set to when the window shows or renders? That is, all other controls are set to AutoFocus="false", the default? What happens if 2 controls have AutoFocus="true"

Not sure I understand the mechanism yet.

AutoFocus="true" just focuses a Component within its AfterRender listener with AutoFocusDelay. AutoFocus is true, AutoFocusDelay is 10 be default.

There is no check if AutoFocus set up for several components. So, it is under developer's responsibility.

michaeld
Aug 02, 2013, 11:26 AM
Thanks!

I'll try it out.

Oh, you didn't answer what happens when 2 controls have autofocus=true

Daniil
Aug 02, 2013, 1:07 PM
Sorry, I thought I answered by this:)


There is no check if AutoFocus set up for several components. So, it is under developer's responsibility.

I meant that it should be not set up for components which are rendered at the same time, because two components cannot be focused simultaneously. Well, nothing critical will happen, I mean no exception, error, just some component will be focused. Probably, the one which is rendered later.

But it should be OK to set up AutoFocus="true" for components from, for example, in different Windows. Though, please note it will be focused only on initial rendering, not on further appearances. But DefaultFocus should focus in that case. So, it is probably a better choice.