Hey everyone!
I would like some help with the display mode of a button.
I have a form that's connected to a SharePoint list that has some columns in it. I also have a button that has an if statement on the DisplayMode property that checks if each field in the form is empty. If any of them are empty, set the DisplayMode to disabled, else DisplayMode is set to edit. The purpose of this button is to make it so they cannot continue on in the app unless all fields in the form have a value or have something selected.
Now, I have some fields that are not visible to everyone who will be using this app. In essence, a LookUp is done in another SharePoint list to see if they have direct reports or not. If they do, some other fields are visible to them. I would like these to also be included in the DisplayMode if statement check on the button but only if they're visible. How would I do this?
Also, if there's a cleaner way input checking in PowerApps I am happy to change my code on the button because it would help with other projects for the future too!
Thank you!
A marked your answer as a solution as it's also a very important thing to make sure you do as well imo - thank you for the assistance, Tony 🙂
Yep, the additional outcome of leveraging the inbuilt validation logic system is that you get timely, contextual error handling (red-bordered fields around missing values, validation help text) when they attempt to submit an invalid form. The only thing is that if you are disabling the submit button until all valid fields are filled, you don't get the red-bordered error handling upon submit. You will need to consider how you let the user know WHY they can't submit the form (Eg: User sees the button disabled, but doesn't know what they need to do to make the button work, is it broken? Is it always supposed to be disabled? Is it permissions?). How you let the user know what they need to do next will depend on the skill of the user and how valuable they see the data that they are entering / validating. The main thing is to make sure the validation method improves the user experience.
Okay so I solved it in a much more seamless way. Here are the steps:
- on the button, in the DisplayMode field I have this code:
If(initialInfoForm.Valid, DisplayMode.Edit, DisplayMode.Disabled)
- I have code set in the Required field of the two data cards set Required to true if it is visible:
If('Temporary Datacard_1'.Visible, true, false)
Testing the code it behaves as required:
- when the two fields are NOT visible, they do not influence what the DisplayMode of the button will be
- when the two fields ARE visible, they are required to have values otherwise they will not be able to click the button!
Because your initial logic is negative (If any of these things are true, disable). It's possibly cleaner to check for the optional values in the same statement, but combine them with the .visible check. Something like:
//NOTE: Untested code
If(
varError = true || IsBlank(leaverDropdown.SelectedItems) || IsBlank(mgrDropdown.Selected) || IsBlank(ctrEndDate.SelectedDate) || IsBlank(lastworkingDate.SelectedDate) || IsBlank(resignationType.Selected.Value) || IsBlank(tlDropdown.Selected.Value) || ((TempOrPermSelector.Visible = true) && (IsBlank(TempOrPermSelector.Selected.Value))) ||
((newTLSelector.Visible = true) && (newTLSelector.Selected.DisplayName = Blank())),
DisplayMode.Disabled,
DisplayMode.Edit
)
Ahhh I seemed to have jumped the gun. I am not too sure if it's because of how big of a statement it is or not but it's still not working 😞 below is my code:
If(
varError = true || IsBlank(leaverDropdown.SelectedItems) || IsBlank(mgrDropdown.Selected) || IsBlank(ctrEndDate.SelectedDate) || IsBlank(lastworkingDate.SelectedDate) || IsBlank(resignationType.Selected.Value) || IsBlank(tlDropdown.Selected.Value) || TempOrPermSelector.Visible = true || newTLSelector.Visible = true,
If(
IsBlank(TempOrPermSelector.Selected.Value) || newTLSelector.Selected.DisplayName = Blank(),
DisplayMode.Disabled,
DisplayMode.Edit
),
DisplayMode.Edit
)
I was too quick to the draw and am hoping it is okay get further help. Thank you!
Omg I didn't even think about doing a nested if statement to perform the check! Thank you kind person 🙂
Hi Jojos,
You should be able to check the status of the .Visible attribute and use that to help decide whether to check the value itself.
Here's an example of controlling the DisplayMode of a button by checking the visibility of a manual TextInput first. If it's not visible you can press the button regardless of the value in the TextInput control. IF the control is visible, then it only allows pressing when there is a value entered:
If (
ManualTestInput.Visible,
If(
IsBlank(ManualTestInput.Text),
DisplayMode.Disabled,
DisplayMode.Edit
),
DisplayMode.Edit
)
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional