We'll show you examples where formulas can be applied to change visibility, required, and more.
In this tutorial you'll learn how to:
This formula determines the visibility of the Description field. It only becomes visible when the Title field isn't empty.
FormulasBasic.Description
Setting Visible (Formula-Target: Field.Settings.Visible)
// Show the field when the title isn't empty any more v2((data) => { return data.Title != ""; });
This formula determines wether the Name field is required. It becomes required if the age isn't specified.
FormulasRequired.Name
Field.Settings.Required (Formula-Target: Field.Settings.Required)
v2((data) => { // If we don't have an age, make the name required var ok = !data.Age; return ok; });
This formula determines wether the ApiKeyV2 field is disabled. It becomes disabled if the UseNewFeatures field is true.
FormulasDisabled.ApiKeyV2
Setting Disabled (Formula-Target: Field.Settings.Disabled)
v2((data) => { return data.UseNewFeatures == true; });
This formula shows a warning if a field has upper case letters, and an error if empty.
FormulasValidation.Title
Field.Validation (Formula-Target: Field.Validation)
v2((data, context) => { const t = data.Title; console.log('Title at start', t); // Check if empty if (t == null || (/^\s*$/).test(t)) return { value: { severity: 'error', message: 'this needs real text'} }; // Show warning if not all lower case if (data.Title.toLowerCase() !== data.Title) return { value: { severity: "warning", message: "we suggest to use lower case only."} }; return data.value; });
Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code
@inherits Custom.Hybrid.Razor14 @using ToSic.Razor.Blade; <!-- unimportant stuff, hidden --> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <h2>Formulas affecting Field Settings</h2> <p>We'll show you examples where formulas can be applied to change visibility, required, and more.</p> <p>In this tutorial you'll learn how to:</p> <ul> <li> Change field and group visibility </li> <li> Make fields required </li> <li> Make fields disabled </li> <li> and much more... </li> </ul> @Html.Partial("./Part NowUsingV2.cshtml") </div> </div> @Html.Partial("../shared/WarnAnonymousIfFeatureIsOff.cshtml") @* Errors and Warnings *@ @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })