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

How to make a text box required when defining actions?

So, i am using a farily simple single page form in powerapps. What i want to do is something like this.

if,

DataCardValue12.Selected.Value = "Food"

 

When defining actions,

I want to make another specific mandatory. i.e. when datacardvalue12 is set to Food. Datacard Allergen is required(Mandatory)

 

What i have tried is add a rule. See screenshot.

 

Thanks heaps in advance 🙂Untitled.png

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Advocate I
Advocate I

Re: How to make a text box required when defining actions?

Create a variable and set the default value to false (field is not required) when the app starts, the screen is visible, or when a button is clicked.  Set the data card Allergen's Required property to your variable.  In the OnChange event for DataCardValue12's textbox to test the text and set the variable appropriately.

For example:

Button - Navigates to edit form's screen OnSelect: 

UpdateContext({varRequireAllergen: false})

Text Input Box - DataCardValue12.OnChange: 

UpdateContext({varRequireAllergen: If(DataCardValue12.Text="Food", true, false)})

Allergen_DataCard - Required property:

varRequireAllergen

The PowerApps default error handling for a required field will take over from there.

 

View solution in original post

3 REPLIES 3
Highlighted
Advocate I
Advocate I

Re: How to make a text box required when defining actions?

Create a variable and set the default value to false (field is not required) when the app starts, the screen is visible, or when a button is clicked.  Set the data card Allergen's Required property to your variable.  In the OnChange event for DataCardValue12's textbox to test the text and set the variable appropriately.

For example:

Button - Navigates to edit form's screen OnSelect: 

UpdateContext({varRequireAllergen: false})

Text Input Box - DataCardValue12.OnChange: 

UpdateContext({varRequireAllergen: If(DataCardValue12.Text="Food", true, false)})

Allergen_DataCard - Required property:

varRequireAllergen

The PowerApps default error handling for a required field will take over from there.

 

View solution in original post

Highlighted
Helper I
Helper I

Re: How to make a text box required when defining actions?

Hey Rob,

Thank-you for your response.

 

I managed to follow through to your instructions but seems to have hit a barrier.

 

I changed the approach very slightly since i am using a choice type and not a text box.

 

In the onSelect of the choice I have:

UpdateContext({varRequireAllergen: false})

in the onChange of the choice I have:

UpdateContext({varRequireAllergen: If(DataCardValue12.Selected.Value = "Food", true, false)})

 

And in the datacard that is supposed to turn mandatory after selecting food, I have 

varRequireAllergen

 

I have noticed that the data card does turn mandatory for a partial second as soon as i change the choice to Food, and changes it back. Your help is really appreciated mate. Thank-you

Untitled.png

Highlighted
Helper I
Helper I

Re: How to make a text box required when defining actions?

I managed to fix it using,

 

UpdateContext({varRequireAllergen: If(DataCardValue12.Selected.Value = "Food", true, false)}) in the onchange and removing everything else.

 

thank-you for your help.

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,101)