cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LRVinNC
Super User
Super User

SetFocus Question

I know the recently added SetFocus function does not work in a gallery or edit form, however, it does say it works with a control on a scrollable screen.  


So, I have a scrollable screen which has a label that sits just above an edit form.  I am trying to use that label to anchor the view so the view is scrolled to the top anytime the screen becomes visible.  Unfortunately, the setfocus seems to be having no effect.  Here's the relevant pieces.  
SetFocus.jpg

 

I didn't write this app but have been trying to help someone else in our organization update it.  As you can see, it uses a Canvas on the scrollable screen (which I have never used previously).  I have tried to put a label on the canvas directly but it won't let me add one there -- it goes to the screen.  Apparently, a scrollable screen requires all the controls to sit inside of datacards (but not forms).  So this OverviewSectionTitle sits as the first control within DataCard4.  The OnVisible for the screen executes the setfocus.  But if I have scrolled down this screen, use the edit button to go to another screen and then come back to this screen, I am still scrolled down this screen where I left it. 

Is this another limitation where setfocus won't work (in which case, it might be worth a note in the docs)? 
Is there any other way to force this screen to always be at the top of the scroll area when the screen becomes visible?

Insights appreciated.

Lori

LRVinNC

------------------
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
2 ACCEPTED SOLUTIONS

Accepted Solutions
Pstork1
Dual Super User III
Dual Super User III

Given the following statement from the first paragraph I suspect the documentation needs clarification.  

 

"The SetFocus function gives a control the input focus. The user's keystrokes are then received by that control, allowing them to type into a text input control or use the Enter key to select a button."

 

The only time a label is available as an Input control is when its in the editor.  I did notice that SetFocus() works at that point.  But I don't think it will have any effect when the app is no in the editor since the label has no input focus at that point.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Since this is a display form, a text input control would not be the solution I would typically pursue, but I figured a way to still make that work.  Check out my blog post for the details.  Thanks @Pstork1 for pushing me down the text input path.  


Personally speaking, I think the SetFocus documentation is a little misleading if it won't work with a label, and should be updated.)

LRVinNC

------------------
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

4 REPLIES 4
Pstork1
Dual Super User III
Dual Super User III

SetFocus is used to set the cursor focus to a control for data input.  Labels can't be used for data input, so it makes sense that they would be ignored by the setfocus() during runtime.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

@Pstork1 

 

According to the documentation setfocus CAN be used with a label, as well as other non-text input controls.

 

SetFocus can only be used with:

LRVinNC

------------------
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Pstork1
Dual Super User III
Dual Super User III

Given the following statement from the first paragraph I suspect the documentation needs clarification.  

 

"The SetFocus function gives a control the input focus. The user's keystrokes are then received by that control, allowing them to type into a text input control or use the Enter key to select a button."

 

The only time a label is available as an Input control is when its in the editor.  I did notice that SetFocus() works at that point.  But I don't think it will have any effect when the app is no in the editor since the label has no input focus at that point.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Since this is a display form, a text input control would not be the solution I would typically pursue, but I figured a way to still make that work.  Check out my blog post for the details.  Thanks @Pstork1 for pushing me down the text input path.  


Personally speaking, I think the SetFocus documentation is a little misleading if it won't work with a label, and should be updated.)

LRVinNC

------------------
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (26,796)