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

 

 

View solution in original post

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
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Power Apps Community Call Jan. 2022 768x460.png

Power Apps Community Call

Please join us on Wednesday, January 19th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,942)