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

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
Helper I
Helper I

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
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 (4,452)