I think creating a Custom page is pretty easy. Once you have the basics you can create the bare bones pretty quickly including some functionality with a Patch statement to update your records. It’s the fine tuning and making sure the custom page works all the time and doesn’t allow users to submit multiple times, or press a button without filling out fields you want them to. If you work on Model-driven Apps (MDA) it’s pretty simple to just set a field as required on a table. With Custom Pages you need a little bit more than that. In this post we will look at a few tips to make fields required in your custom pages, or at least give the appearance of them being required.
First, it’s actually the label we will add some logic to rather than the text box we want them to fill out. Here we have a label that asks the user to provide a reason. So lblReason is for txtReason which is the multi-line text box below it.

Click to view in detail
The first thing we can do is prevent the Submit button from being pressed if the text box is empty. For this, go to the Button then the Display Mode. If you’ve read any of the other posts I’ve done on Custom pages you will have seen then one that disables the button after it is pressed the first time, setting a varButton variable as true. We’ll include that same approach in the displaymode formula on the button. The logic is as follows:
It enables (DisplayMode.Edit) only when:
txtReason.Valueis not blank, andvarButtonis false.
That means if varButton is true, or the text box is empty, the button is disabled.
If(
!IsBlank(txtReason.Value) && varButton = false,
DisplayMode.Edit,
DisplayMode.Disabled
)

Click to view in detail
Now that takes care of them not being able to submit without anything in that value, but it would be good to indicate that on the label too in some way. There are a couple of options I will show, with the last being my preferred, but this gives you choices. First we can add a formula to the Text itself. Right after the label text closed quote, we can add the & symbol then have a formula that adds an asterisk if the txtReason.Value (the text box) is blank/empty. If not, there is no asterisk added. Better!

Click to view in detail
What about a colour change too? No one likes their work marked in red so let’s show it in red if the txtReason.Value is blank and if there is a value the label will be in black. Add this formula to the Color property.

Click to view in detail
Ok so the above options work… but you know what works better and looks nicer? Using an HTML component instead of a text one. This allows you to add HTML within the text which means you can change the font color and weight rather than having the whole thing black or red.

Click to view in detail
If you know HTML then this should be really easy for you. If you don’t, a few simple things you can use. Start in the quotes with your HTML and you can add
"<center>Please provide a reason for returning this Lead to Marketing" &
If(IsBlank(txtReason.Value), "<font color=red><b> *</b></font>", "")
You can see with the comparison, it is less harsh just making the asterisk red rather than the whole thing. Make sure you remove the original label if you had one and just leave the HTML one.

Click to view in detail
You can also add in a Tooltip at the bottom of the Properties of the HTML component.

Click to view in detail
Then when someone hovers their mouse over the label they will see it for further clarification.

Click to view in detail
Save and publish your custom page, then publish the MDA to make sure it picks up your changes. Now when someone opens the custom page, they will not be able to submit it unless they fill out the required fields you have set!

Click to view in detail
Discussion
Loading comments…
Join the discussion
Have a question or something to add? I'd love to hear from you. All comments are reviewed before appearing on the site.