web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / retain focus in textinput
Power Apps
Answered

retain focus in textinput

(0) ShareShare
ReportReport
Posted on by 54

Dear Team,

 

I want to retain focus in a text input box when the given value by the user is beyond specified limits

for example: if I set the min and max properties to 1 and 10 respectively, if the end user types any value that is either less than 0 or more than ten, then cursor or focus should not leave that particular control (say text box)

 

I have used BorderColorChange to Red on the given control's condition failure, but not able to retain focus in that particular control.

 

the following is the code that I used on OnChange Event Handler for text box, but this setfocus is not working and I am able to ove out of control.

 

If(Value(txtOverAll.Text) > varReqEnt-varUpdEntries, Notify("OVER-ALL Value cannot be greater than " & varReqEnt-varUpdEntries, NotificationType.Error), varReqEnt-varUpdEntries);
SetFocus(txtOverAll);

 

for example in VB, we have onExit Event, where, on a particular condition failure, the focus is retained with SetFocus method., looking for similar functionality.

 

can anyone please help.

 

with regards

Repath Athyala.

Categories:
  • KrishnaV Profile Picture
    5,023 on at

    Hi @Riphath ,

     

    You are doing everything right just make a small change in your if condition

     If(Value(txtOverAll.Text) > varReqEnt-varUpdEntries, 
     Notify("OVER-ALL Value cannot be greater than " & varReqEnt-varUpdEntries, NotificationType.Error);
     SetFocus(txtOverAll); // These 2 staements work when the condition is true
     , varReqEnt-varUpdEntries); // This staement work when the condition is false

     

    I hope this resolved your issue if you see any challenge let me know I am always happy to help.

     

    Regards,

    Krishna
    If this post helps, then please consider Accept it as the solution and give thumbs-up to help the other members find it more.

     

  • Riphath Profile Picture
    54 on at

    @KrishnaV 

     

    Thankyou for your response, I have used exactly the same code as you were suggesting, but still the cursor moves out of the control.

     

    I have written on the OnChange event of text box:, guess, I am correct...!

     

    the following is the code for your reference:

    If(Value(txtOverAll.Text) > varReqEnt-varUpdEntries,
    Notify("OVER-ALL Value cannot be greater than " & varReqEnt-varUpdEntries, NotificationType.Error);
    SetFocus(txtOverAll); varReqEnt-varUpdEntries);

     

    with regards

    Repath Athylala

  • KrishnaV Profile Picture
    5,023 on at

    Hi @Riphath ,

     

    I am happy it helped you to solve your issue, I was under the impression that you have this in OnChange event. By the way your if condition is not having any else scenario. I hope, you made it intentionally.

     

    I hope this resolved your issue if you see any challenge let me know I am always happy to help.

     

    Regards,

    Krishna
    If this post helps give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.

     

     

  • Riphath Profile Picture
    54 on at

    @KrishnaV , sorry to say, that your solution did not help me.

     

    to brief out the context again: 
    Say I have a text box and I want to limit the input from 1 to 10, (I mean, no lower to one and no higher to 10)... when someone tries to enter any number out of the given range, then I want to retain the focus in the same control (textbox) until he enters the correct value / expected value.

     

    What should be the code that you would prefer to write, so that, I can replicate the same.  Please help.

     

    with regards

    Repath Athyala.

  • KrishnaV Profile Picture
    5,023 on at

    hi @Riphath ,

     

    In Power Apps there is no OnBlur event you see in JavaScript like in Classic .Net development. So all what you can do is restrict the maxlength to that input text control to 10 and handle the length of the string on submit / next button (if you are navigating to next screen).

     

    If(Len(TextInput11.Text)<1 && Len(TextInput11.Text)>10, SetFocus(TextInput11))

     

    The above code you can use as part of button onSelect event.

     

    There is one idea submitted in PowerApp community, please vote for that so it will be implemented by Microsoft
    https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Add-OnBlur-Event-Support/idi-p/215794

     

    I hope this resolved your issue if you see any challenge let me know I am always happy to help.

     

    Regards,

    Krishna
    If this post helps give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.

  • Verified answer
    Riphath Profile Picture
    54 on at

    @KrishnaV 

    Hi Krishna,

    Sorry to for responding late., unfortunately, we don't have SETFOCUS() for controls in forms.  

     

    The following text is pasted as:is for end-user reference.,

    this is in the basic PowerApps Documentation, unfortunately, could not refer till now., posting the same in public interest.

     

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-setfocus

    "You cannot set the focus to controls that are within a Gallery control, Edit form control, or Component. SetFocus can be used with a control in a scrollbale screen.

    You can only set the focus to controls on the same screen as the formula containing the SetFocus call."

     

    with regards

    Repath Athyala.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 283

#3
Mohsin Ali Profile Picture

Mohsin Ali 221

Last 30 days Overall leaderboard