cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dakridge
Advocate II
Advocate II

Setfocus on a newly visible item

In my app I have an Input Box that once the user clicks, opens a Search Box that the user can search a name and then choose and repopulate the Input Box.  I set the OnSelect state of the Input Box with a variable that will trigger the visible state of the Search Box.  I then put under the set command a SetFocus to move it to the newly visible Search Box. 

 

When the user clicks the Input Box makes the Search Box visible, but you have to click the Input Box again to make it move focus.  Not sure why it will not do both commands in the OnSelect of the Input Box. 

David K Akridge
Chief Information Officer, Mobile County Public Schools
1 ACCEPTED SOLUTION

Accepted Solutions
PowerAddict
Super User
Super User

Hi @dakridge

 

I would like to first say thank you to you for finding this weird behavior. I can confirm the following behavior: 

  1. If selecting the 1st text box makes the 2nd text box visible AND also tries to set focus on the 2nd text box, the set focus part doesn't work
  2. However, if we click again, then the set focus works fine
  3. Also, if the 2nd text box is visible from the beginning, then set focus works the 1st time itself

 

While I cannot say why this happens, if this is preventing you from achieving the desired behavior, I do have a workaround.

  • Add a label on top of the 2nd text box.
  • Set the visible property of the 2nd text box to true
  • Set the OnSelect of the 1st text box to 
Set(showVar, false)
  • Set the visible property of the label to 
!showVar
  • Ensure showVar is set to false when you come to the screen so the label is visible and covers the 2nd text box
  • Set the OnSelect of text box 1 to 
Set(showVar, true); SetFocus(TextBox2)​

Here is the behavior in both scenarios:

TextBox.gif

Let me know if this helps. 

 

---
If you like this reply, please give kudos (Thumbs Up). And if this solves your problem, please mark this reply as a solution by selecting Accept as Solution. This makes it easier for others to find answers to similar questions. 

 

Thanks!

Hardit Bhatia

Microsoft Business Applications MVP

Blog | Twitter | LinkedIn | Facebook | YouTube  |  Email

 

 

View solution in original post

2 REPLIES 2
PowerAddict
Super User
Super User

Hi @dakridge

 

I would like to first say thank you to you for finding this weird behavior. I can confirm the following behavior: 

  1. If selecting the 1st text box makes the 2nd text box visible AND also tries to set focus on the 2nd text box, the set focus part doesn't work
  2. However, if we click again, then the set focus works fine
  3. Also, if the 2nd text box is visible from the beginning, then set focus works the 1st time itself

 

While I cannot say why this happens, if this is preventing you from achieving the desired behavior, I do have a workaround.

  • Add a label on top of the 2nd text box.
  • Set the visible property of the 2nd text box to true
  • Set the OnSelect of the 1st text box to 
Set(showVar, false)
  • Set the visible property of the label to 
!showVar
  • Ensure showVar is set to false when you come to the screen so the label is visible and covers the 2nd text box
  • Set the OnSelect of text box 1 to 
Set(showVar, true); SetFocus(TextBox2)​

Here is the behavior in both scenarios:

TextBox.gif

Let me know if this helps. 

 

---
If you like this reply, please give kudos (Thumbs Up). And if this solves your problem, please mark this reply as a solution by selecting Accept as Solution. This makes it easier for others to find answers to similar questions. 

 

Thanks!

Hardit Bhatia

Microsoft Business Applications MVP

Blog | Twitter | LinkedIn | Facebook | YouTube  |  Email

 

 

Leave it to me to be trying to do something strange.  Thank you for confirming and for the work around.  

David K Akridge
Chief Information Officer, Mobile County Public Schools

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (3,800)