cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GDSI
Frequent Visitor

In Gallery, Validate on control based on another control.

In a gallery (galItems), there is a dropdownlist (ddlStatus) for Status (Pass, Fail, Ignore), and a textbox (txtComments) field. If the Status="Fail", the Comments field cannot be blank. 

 

What is the PowerApps way to implement this validation when a Save button is selected?

 

This page doesn't really provide enough information nor good examples: Validate function in Power Apps - Power Apps | Microsoft Docs

3 REPLIES 3
JR-BejeweledOne
Super User
Super User

You can't actually 'require' fields in Power Apps.    What you can do is a workaround.    I am going to give an example that presumes your save button is in the individual gallery item.

 

Add a 10 x 10 label with an Asterisk in it (red color) and put it to the right or left of your comment field in the gallery.   Set it's visible property to:

ddlStatus.selected.XXX = "Fail" && IsBlank(txtComments)

 

Follow the same logic and set the displaymode property of the save button to view.

 

If(
  ddlStatus.Selected.XXX = "Fail" && IsBlank(txtComments), DisplayMode.View, DisplayMode.Edit
)

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
v-qiaqi-msft
Community Support
Community Support

Hi @GDSI,

Do you want to validate the status and comments field when you submit?

Could you please share a bit more about your scenario?

 

Firstly, you should put a validation within the Comments field by setting the HintText text input as below:

If(ddlStatus.Selected.Value="Fail"&& IsBlank(TextInput1.Text),"Here should have inputs!","")

Set the save button OnSelect property as below:

If(!IsBlank(TextInput1.HintText),Notify("Comments field cannot be blank, please fill in!",Error))
Best Regards,
Qi
GDSI
Frequent Visitor

Here's what I did...

 

In txtComments.Fill: 
If(ddlResult.Selected.Value = "At Risk" && IsBlank(txtComments),
RGBA(255, 0, 0, 1),
RGBA(255, 255, 255, 1)
)

 

In btnSubmit.OnSelect: 

Set(varValidationCnt,
CountIf(galObsItems.AllItems.lblValidateComment,lblValidateComment.Text="true")
);

If(varValidationCnt>0,
Notify("At Risk items must have a comment. Please update " & varValidationCnt & " row(s)"),
If(SubmitForm(frmObsv),
If(CountRows(colObsItems) > 0,
Patch('MySharePointListName', colObsItems);
Notify(CountRows(colObsItems) &
" detail item(s) were saved", NotificationType.Information);
Clear(colObsItems);
Navigate(scrSearchObs,ScreenTransition.Fade)
)
)
)

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

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