cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rohinMVP
Resolver I
Resolver I

How can I set focus on control without data?

I have an edit form in which many fields are Required.

 

The validation fires fine for me, but how can I set focus on a control that doesn't have data?

 

Also, when I have a custom datacard, how can I get the red border on the control?

(I am saving to a text field, but I want to show a dropdown on the form)

4 REPLIES 4
yashag2255
Dual Super User II
Dual Super User II

Hi @rohinMVP 

 

You can change the border color of the control when it is empty by using the below expression:

If(IsBlank(ControlName.Text), RGBA(FocusColor), RGBA(Normal Color))

 

Can you share more details on the configuration for this dropdown, maybe through some example or screenshot, so that we might be able to help you better.

 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

StormEAnderson
Resolver I
Resolver I

For the auto-focus part, the SetFocus() Method is what you are going to want to look at https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-setfocus

 

It does have some limitations, but you can use it for most form components you'd expect and you can call it wherever you are calling your EditForm() or NewForm() function to auto-focus to the field of your choosing. Make sure to point it at the component itself and not the parent datacard in the form.

 

As for the custom card, If I understand you right I'd take the following approach to implementing the dropdown:

  1. Add your text field to the form and then unlock it under the Properties Tab > Advanced section
  2. Once unlocked, insert a dropdown into the same card, and place it over the text box field.
  3. Set the Dropdown.default = Parent.Default
  4. Set the text box (datacard) default that you covered with the dropdown to then be Dropdown1.SelectedText.Value.
  5. You can then program the dropdown border color with whatever formula you like. You could also your focus to the dropdown directly if that is what you were intending.

Hope this helps!

rohinMVP
Resolver I
Resolver I

Hi @yashag2255 

 

with the code you provided it would be having FocusColor on load.

 

I wanted to have it change color only when I try to submit the form (just like the normal Required validation).

yashag2255
Dual Super User II
Dual Super User II

@rohinMVP 

 

In that case, you can setup the configuration as:

 

RequiredControls -> Border Color -> If(varHighlight && IsBlank(ControlName.Text), RGBA(highlightcolor),RGBA(normal color))

 

Save Button ->  If(IsBlank(Control1.Text) || IsBlank(Control2.Text) || IsBlank(Control3.Selected.Value), Set(varHighlight,true), Set(varHighlight,false)) ;If(varHighlight=false, SubmitForm(FormName)) 

 

Here, we are checking whether all the required fields are filled, it they are we are setting varHighlight  as false, and submitting the form, otherwise we are setting varHighlight as true and highlighting the fields.

 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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