Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Search Forums » Search Results » View Thread |
Messages 1 to 8 of 8 total |
Focus Won't Stick In TPagePanel's OnChange Event |
Sun, Feb 11 2018 10:19 PM | Permanent Link |
Frederick Chin | I have a TPagePanel with 2 TPages. Each TPage has several TEdits. What I want to do is when a user clicks the TPage or if the TPagePanel's ActivePage changes programmatically, I want focus to be on the first TEdit of that TPage. In the TPagePanel's OnPageChange event, I have added the following code:- if NewPage=Page1 then TEdit1.Setfocus else if NewPage=Page2 then TEdit2.Setfocus; Result:=True; It seems that the Setfocus method is called but focus is lost for some reason. It seems that something else is happening after the OnPageChange event is called. I believe that there should be an OnPageAfterChange event so that the setfocus call will stick. Is my thought about a new event valid or am I putting the SetFocus call in the wrong place? -- Frederick |
Mon, Feb 12 2018 4:45 AM | Permanent Link |
Matthew Jones | Frederick Chin wrote: > Is my thought about a new event valid or am I putting the SetFocus call in the wrong place? I suspect that the event is happening before the page is made visible, so you can initialise it etc. Thus the focus will change, but the automatic code will then kick in and update it (or the edit is not visible so can't be focussed). Probably worth putting in a load of event handlers to check the order, but I'd be looking at the OnShow for the TPage to see if that is after the switch. -- Matthew Jones |
Mon, Feb 12 2018 8:54 AM | Permanent Link |
Frederick Chin | "Matthew Jones" wrote: /* I suspect that the event is happening before the page is made visible, so you can initialise it etc. Thus the focus will change, but the automatic code will then kick in and update it (or the edit is not visible so can't be focussed). */ I think this is what is happening because I put a label to track the event and the label is updated but the focus is lost. /* Probably worth putting in a load of event handlers to check the order, but I'd be looking at the OnShow for the TPage to see if that is after the switch. */ I would prefer that the event control be handled by the TPagePanel so that there is one place for the page events. As for the OnShow of the TPage, I did have some success. On my two TPages, the first object is a TEdit for the first page while there is a TCheckBox and TEdit in the second page. In the OnShow event of the TPages, I put the code as follows:- if TPage(Sender).Name='FirstPage' then Edit1.Setfocus else if TPage(Sender).Name='SecondPage' then begin CheckBox1.Setfocus; end; If I click on the first page, the edit box is focused but in the second page, EWB just refuses to set focus on the check box. I have no idea why. If I change the "CheckBox1.Setfocus" to "Edit2.Setfocus", the field is focused. I tried to work around it by first focusing on the edit box and then call Edit2.Tab(True) which is supposed to perform a Shift+Tab to the check box. Again, no go. -- Frederick |
Mon, Feb 12 2018 9:04 AM | Permanent Link |
Matthew Jones | Frederick Chin wrote: > if TPage(Sender).Name='FirstPage' then That would be better as if Sender = FirstPage then so that changing the name gets a compile error. But I think you are just falling over the thorny issue of JavaScript and the DOM being awkward to sync. In one case I ended up using a timer to set the focus, but you end up getting awkward situations even then. -- Matthew Jones |
Mon, Feb 12 2018 9:10 AM | Permanent Link |
Frederick Chin | "Matthew Jones" wrote: /* That would be better as if Sender = FirstPage then */ Thanks for the tip. /* so that changing the name gets a compile error. But I think you are just falling over the thorny issue of JavaScript and the DOM being awkward to sync. In one case I ended up using a timer to set the focus, but you end up getting awkward situations even then. */ Ugh. Using a timer does sound messy and unwieldy. I'll gravitate for a single OnAfterChange event. -- Frederick |
Mon, Feb 12 2018 2:47 PM | Permanent Link |
Raul Team Elevate | On 2/11/2018 10:19 PM, Frederick Chin wrote: > It seems that the Setfocus method is called but focus is lost for some reason. It seems that something else is happening after the OnPageChange event is called. > > I believe that there should be an OnPageAfterChange event so that the setfocus call will stick. > > Is my thought about a new event valid or am I putting the SetFocus call in the wrong place? Just a wild guess to try with Create a new SetFocus procedure and call it from OnPageChange using the async (https://www.elevatesoft.com/manual?action=viewtopic&id=ewb2&topic=Asynchronous_Calls) This woudl call it in async manner and might run after other framework events run - worth a quick test Raul |
Mon, Feb 12 2018 4:07 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Frederick, << It seems that the Setfocus method is called but focus is lost for some reason. It seems that something else is happening after the OnPageChange event is called. >> Yes, the OnPageChange event happens *before* anything happens with the pages, giving you an opportunity to prevent the page change. OnShow is also a no-go because the tab click causes a focus call on the page that occurs *after* the new page is shown. So, yes, there needs to be an OnPageChanged event or something similar for the TPage control, in addition to some more code to finesse the SetFocus method for the TPage control. The existing behavior is present to allow for a TPage to behave like any container control in EWB where clicking on the container area causes the currently-focused control to lose focus, which is important for touch environments where you want to remove the soft keyboard from the screen. I've attached a unit that makes these corrections, which you can use as a hotfix for now. Tim Young Elevate Software www.elevatesoft.com Attachments: WebPages.wbs |
Mon, Feb 12 2018 8:32 PM | Permanent Link |
Frederick Chin | Tim, /* I've attached a unit that makes these corrections, which you can use as a hotfix for now. */ Thanks. The unit solves the focus issue. -- Frederick |
This web page was last updated on Sunday, December 1, 2024 at 03:59 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |