Advanced Formula APIs
In this tutorial you'll learn some of the advanced APIs such as:
- Detect if features are enabled new in v14
- Ability to stop formulas from running new in v16
- Get user information about the current user new in v16
Important: Now using Formulas V2 🆕 in 2sxc 16
Formulas V2 has intellisense, stoppability, support for promises and more.
Important: The feature "Public Use of Edit Form" is disabled
If you want this demo to run for anonymous users you would need it. Register your site on patrons.2sxc.org to get access to the feature.Most formulas will run on every change.
Special formulas such as these returning a promise will auto-stop (unless stop: false).
But if you want to stop running your formula at any time, you can also return a value with stop: true.
todo
todo todo
Click on the (Σ) button above to see the edit-UI with the formula.
Formulas of FormulaStop.Title
Field.Value (Formula-Target: Field.Value)
v2((data, context) => { alert("you will see this alert once, after this the formula won't run any more."); return { value: "this is a new title", stop: true, }; });
Try it:
Show a warning or info based on the feature GoogleTranslate being enabled.
Click on the (Σ) button above to see the edit-UI with the formula.
Formulas of FormulasFeatures.GoogleTranslateWarning
Field.Settings.Visible (Formula-Target: Field.Settings.Visible)
v2((data, context) => { return !context.features.isEnabled("EditUiTranslateWithGoogle"); });
Formulas of FormulasFeatures.GoogleTranslateInfo
Field.Settings.Visible (Formula-Target: Field.Settings.Visible)
v2((data, context) => { return context.features.isEnabled("EditUiTranslateWithGoogle"); });
Try it:
This formula shows information about the user and shows a warning if the user is not logged in.
Click on the (Σ) button above to see the edit-UI with the formula.
Formulas of FormulasUser.UserInformation
Field.Settings.Notes (Formula-Target: Field.Settings.Notes)
v2((data, context) => { return data.default .replace('[name]', context.user.name ?? "unknown") .replace('[userid]', context.user.id) .replace('[isanonymous]', context.user.isAnonymous) .replace('[issiteadmin]', context.user.isSiteAdmin); });
Formulas of FormulasUser.WarningAnonymous
Field.Settings.Visible (Formula-Target: Field.Settings.Visible)
v2((data, context) => { return context.user.isAnonymous; });