cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Cooper
New Member

Make datacards required once visible in form / Make datacards required if different datacard has a value entered in it

Hello,

 

I have a NewForm connected to an excel file. There are checkboxes on the page which make certain datacards visible. When these datacards become visible upon selection of the checkbox I'd like them to be required fields. When they are hidden I would like them to be unrequired.

 

Alternatively, I'd like to make datacards required if a different data card has a value entered in it. for example, if there is a data card for Product Description and Product Code, I'd like to make the product code datacard required when there is a value entered in the product description datacard.

 

Both of these solutions are equally valid and any help is much appreciated!

 

Thanks!

Cooper

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hi @Cooper 

 

For making certain data cards visible only when the checkbox is checked, you can set a global variable when the checkbox is checked, this can be done by updating the "OnCheck" property as:
Set(CheckboxChecked, true)
 
"OnUncheck" -> Set(CheckboxChecked, true)
 
Also, set the visible property of your datacards as: CheckboxChecked
 
Regarding the second use case, you can modify your datacard's required property based on the same variable created as part of first item:
 
DataCard -> Required -> If(CheckboxChecked,true,false)
 
You can use this expression on all the datacards wherever required.

 

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!

View solution in original post

Hi @yashag2255 

 

This was a great solution but I have two edits to make it more clear for future people who come across this post.

 

1. Set the "OnUncheck" property to Set(CheckboxChecked, false) .... previously you had the Oncheck and OnUncheck properties both set to "true" and this kept powerapps from understanding the boolean nature of this function.

 

2. set the visible property of the datacards to If(CheckboxChecked,true,false). Yes, this is the same formula that you will put in the required property for the datacards. By doing this instead of setting the visible property to "CheckboxChecked," by default the datacards will not appear until the checkbox is checked and when you check the box it will make the fields required. both the visibility and requirement of these datacards will toggle with the checkbox. When you set the visible property to just "CheckboxChecked," by default the datacards are visible when you first enter the page even though the checkbox is unchecked by default (you should not be able to see the cards until the box is checked). Then, upon the first check of the box they become required (you see a star appear next to the title) and upon first uncheck they disapear. After that, the functionality works fine. Using the If statement just makes it so that when you first enter the page with the datacards and checkboxes that the datacards are not visible until you check that box.

 

everything else in your response worked great. Thanks so much!!

View solution in original post

3 REPLIES 3
Akatamaoka
Advocate II
Advocate II

For your first scenario, it sounds like you can set the "Visible" and "Required" properties of the datacard to the Value of the Checkbox.

 

To test this, I tried to recreate the issue with input box fields instead of connecting to an Excel spreadsheet, but it should work the same way.

 

For my test:

  1. Add 2 checkboxes, Checkbox1 and Checkbox2
  2. Add 2 text input boxes, TextInput1 and TextInput2
  3. Set the "Visible" properties of the two input boxes to their corresponding checkboxes (here is where you would also change the "Required" properties
    TextInput1 Visible property: 
    Checkbox1.Value
    TextInput2 Visible property:
    Checkbox2.Value
  4. Checkboxes work as "true" or "false", so if a checkbox is checked, it's true, and if the Visible/Required properties are set to the value of the checkbox, they will also be true.

checkboxes.png

Hi @Cooper 

 

For making certain data cards visible only when the checkbox is checked, you can set a global variable when the checkbox is checked, this can be done by updating the "OnCheck" property as:
Set(CheckboxChecked, true)
 
"OnUncheck" -> Set(CheckboxChecked, true)
 
Also, set the visible property of your datacards as: CheckboxChecked
 
Regarding the second use case, you can modify your datacard's required property based on the same variable created as part of first item:
 
DataCard -> Required -> If(CheckboxChecked,true,false)
 
You can use this expression on all the datacards wherever required.

 

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!

Hi @yashag2255 

 

This was a great solution but I have two edits to make it more clear for future people who come across this post.

 

1. Set the "OnUncheck" property to Set(CheckboxChecked, false) .... previously you had the Oncheck and OnUncheck properties both set to "true" and this kept powerapps from understanding the boolean nature of this function.

 

2. set the visible property of the datacards to If(CheckboxChecked,true,false). Yes, this is the same formula that you will put in the required property for the datacards. By doing this instead of setting the visible property to "CheckboxChecked," by default the datacards will not appear until the checkbox is checked and when you check the box it will make the fields required. both the visibility and requirement of these datacards will toggle with the checkbox. When you set the visible property to just "CheckboxChecked," by default the datacards are visible when you first enter the page even though the checkbox is unchecked by default (you should not be able to see the cards until the box is checked). Then, upon the first check of the box they become required (you see a star appear next to the title) and upon first uncheck they disapear. After that, the functionality works fine. Using the If statement just makes it so that when you first enter the page with the datacards and checkboxes that the datacards are not visible until you check that box.

 

everything else in your response worked great. Thanks so much!!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,091)