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
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 )
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))
Here's what I did...
If(ddlResult.Selected.Value = "At Risk" && IsBlank(txtComments),
RGBA(255, 0, 0, 1),
RGBA(255, 255, 255, 1)
Notify("At Risk items must have a comment. Please update " & varValidationCnt & " row(s)"),
If(CountRows(colObsItems) > 0,
" detail item(s) were saved", NotificationType.Information);