Skip to content

Commit 9ca9b3f

Browse files
committed
more samples + auto-size
1 parent fd57245 commit 9ca9b3f

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

formulas/_110 Values.cshtml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,38 @@
2424
Title = "Set the Value if it's empty",
2525
Instructions = "This formula sets the value of a field if it's empty. As long as it's not empty, the user can type anything he/she wants. ",
2626
ContentType = "FormulasIfEmpty",
27-
FieldName = "Title",
28-
Size = 100
27+
FieldName = "Title"
2928
})
3029

3130
@* Combine Values of Fields *@
3231
@Html.Partial("_PartFormulas.cshtml", new {
3332
Title = "Generate a Field Combining Others",
3433
Instructions = "This formula combines the values of 3 fields into a URL Slug. ",
3534
ContentType = "FormulasCombineValues",
36-
FieldName = "UrlKey",
37-
Size = 100
35+
FieldName = "UrlKey"
3836
})
3937

38+
<hr>
39+
<h2>Get Data for a Field from a Web API</h2>
4040

41+
@* Combine Values of Fields *@
42+
@Html.Partial("_PartFormulas.cshtml", new {
43+
Title = "Get value for a field from a WebAPI",
44+
Instructions = "This formula is very advanced, and will initialize a fields value (if empty) from a WebAPI call. ",
45+
ContentType = "FormulasWebApiText",
46+
FieldName = "Title"
47+
})
4148

4249

50+
<hr>
51+
<h2>Date Examples</h2>
4352

4453
@* Date Examples #1 *@
4554
@Html.Partial("_PartFormulas.cshtml", new {
4655
Title = "Date - Prefill but leave editable",
4756
Instructions = "This formula sets the initial value to the current date (if the field is empty). You can try it by deleting the value, once you leave the field it's updated again. ",
4857
ContentType = "FormulasDates",
49-
FieldName = "RightNow",
50-
Size = 125
58+
FieldName = "RightNow"
5159
})
5260

5361
@* Date Examples #2 *@
@@ -56,6 +64,5 @@
5664
Instructions = "This formula sets the third field to the current date/time + an offset the user can choose in a dropdown. "
5765
+ "Note that since we do some calculations, we must make sure the result is time-zone cleaned. ",
5866
ContentType = "FormulasDates",
59-
FieldName = "PublishWhen",
60-
Size = 125
67+
FieldName = "PublishWhen"
6168
})

formulas/_114 DropDowns.cshtml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
Title = "Change dropdown options: Country to Offices",
2525
Instructions = "This formula changes the values in the second dropdown based on the country picked first. ",
2626
ContentType = "FormulasDropdown",
27-
FieldName = "Office",
28-
Size = 160
27+
FieldName = "Office"
2928
})
3029

3130
@* Change Dropdown Values #2 *@
3231
@Html.Partial("_PartFormulas.cshtml", new {
3332
Title = "Change dropdown options: Limited or More Options",
3433
Instructions = "This formula changes the values in the second dropdown if the user wants more options. ",
3534
ContentType = "FormulasDropdownDirections",
36-
FieldName = "Options",
37-
Size = 160
35+
FieldName = "Options"
3836
})

formulas/_115 Settings.cshtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@
6060

6161

6262

63+
@* Errors and Warnings *@
64+
@Html.Partial("_PartFormulas.cshtml", new {
65+
Title = "Warnings and Errors based on Value",
66+
Instructions = "This formula shows a warning if a field has upper case letters, and an error if empty.",
67+
ContentType = "FormulasValidation",
68+
FieldName = "Title"
69+
})
70+

formulas/_116 Groups.cshtml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,15 @@
3939
Title = "Group Name - Emoji summary",
4040
Instructions = "This formula changes the Name of the ProductGroup field. The name becomes \"Product ✅\" if all group fields are filled out and \"Product ✏️\" if not.",
4141
ContentType = "FormulasEmojiSummary",
42-
FieldName = "ProductGroup",
43-
Size = 150
42+
FieldName = "ProductGroup"
4443
})
4544

4645
@Html.Partial("_PartFormulas.cshtml", new {
4746
Title = "Helptext",
4847
Instructions = "This formula adds a help text based on the ProductCode Field text. If the ProductCode field contains \"n0t0k\" the helptext \"This product code is deprecated. Please request a new product code. \" is added, or if it contains spaces the helptext \"Please remove all spaces from your product code.\" is added.",
4948
ContentType = "FormulasHelpText",
5049
FieldName = "ProductCode",
51-
More = "prefill:ProductCode=n0t0k code",
52-
Size = 175
50+
More = "prefill:ProductCode=n0t0k code"
5351
})
5452

5553

@@ -60,6 +58,5 @@
6058
+ "Normally it would do this based on how complete data in that section is or based on other criterias. "
6159
+ "This is often used to improve initial state of a form based on how much data is already filled in. ",
6260
ContentType = "FormulasRunAtStart",
63-
FieldName = "GroupRandomlyOpen",
64-
Size = 200
61+
FieldName = "GroupRandomlyOpen"
6562
})

formulas/_PartFormulas.cshtml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@inherits Custom.Hybrid.Razor14
22
@using ToSic.Razor.Blade;
3+
@using System.Linq;
34
@{
45
var fHlp = CreateInstance("Helpers.cs");
56
var formulas = fHlp.GetFormulas(DynamicModel.ContentType, DynamicModel.FieldName);
@@ -22,7 +23,12 @@
2223
<h3>Formulas of <code>@(DynamicModel.ContentType).@DynamicModel.FieldName</code></h3>
2324
@foreach (var formula in formulas)
2425
{
26+
// try to auto-calc height
27+
var formulaCode = formula.Formula;
28+
var lines = formulaCode.Split(new string[] { "\n" }, System.StringSplitOptions.RemoveEmptyEntries).Length;
29+
var autoSize = lines * 23;
30+
// @lines
2531
<p><strong>@formula.Title</strong> (Formula-Target: @formula.Target)</p>
26-
@Html.Partial("../shared/_result.cshtml", new { Result = formula.Formula, Language = "javascript", Size = DynamicModel.Size ?? 100 })
32+
@Html.Partial("../shared/_result.cshtml", new { Result = formulaCode, Language = "javascript", Size = DynamicModel.Size ?? autoSize })
2733
}
2834
</div>

0 commit comments

Comments
 (0)