cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Riphath
Helper I
Helper I

retain focus in textinput

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.

1 ACCEPTED SOLUTION

Accepted Solutions

@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.

View solution in original post

6 REPLIES 6
KrishnaV
Super User III
Super User III

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.

 


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

@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

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.

 

 


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

@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.

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.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

@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.

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

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (47,591)