Formity operators
Schema operators
Operators used to create the Formity schema.
$schema$form
Returns the form schema element.
{
"$schema$form": {
"values": "expression",
"render": "expression"
}
}
The values
property takes the input values as variables and returns the object expected by the form element's values
function.
The render
property takes the arguments of the form element's render
function as variables and returns what needs to be rendered.
expry([
{
$schema$form: {
values: {
name: ["", []],
surname: ["", []],
age: [20, []],
},
render: {
// ...
},
},
},
// ...
]);
$schema$yield
Returns the yield schema element.
{
"$schema$yield": {
"next": "expression",
"back": "expression"
}
}
The next
property takes the input values as variables and returns the array expected by the yield element's next
function.
The back
property takes the input values as variables and returns the array expected by the yield element's back
function.
expry([
// ...
{
$schema$yield: {
next: [{ name: "$$name", surname: "$$surname", age: "$$age" }],
back: [],
},
},
// ...
]);
$schema$return
Returns the return schema element.
{ "$schema$return": "expression" }
The expression takes the input values as variables and returns the values to be returned.
expry([
// ...
{
$schema$return: {
fullName: { $concat: ["$$name", " ", "$$surname"] },
age: "$$age",
softwareDeveloper: false,
interested: "$$interested",
},
},
]);
$schema$variables
Returns the variables schema element.
{ "$schema$variables": "expression" }
The expression takes the input values as variables and returns the variables to be created.
expry([
// ...
{
$schema$variables: {
i: 0,
languagesRatings: [],
},
},
// ...
]);
$schema$cond
Returns the condition schema element.
{
"$schema$cond": {
"if": "boolean",
"then": ["element", "..."],
"else": ["element", "..."]
}
}
The if
property takes the input values as variables and returns a boolean value.
The then
property contains the elements to use when it is true, and the else
property contains the elements to use when it is false.
expry([
// ...
{
$schema$cond: {
if: "$$softwareDeveloper",
then: [
// ...
],
else: [
// ...
],
},
},
]);
$schema$loop
Returns the loop schema element.
{
"$schema$loop": {
"while": "boolean",
"do": []
}
}
The loop
property takes the input values as variables and returns a boolean value.
The do
property contains the elements to use while it is true.
expry([
// ...
{
$schema$loop: {
while: { $lt: ["$$i", { $length: "$$languages" }] },
do: [
// ...
],
},
},
// ...
]);
$schema$switch
Returns the switch schema element.
{
"$schema$switch": {
"branches": [
{ "case": "boolean", "then": ["element", "..."] },
{ "case": "boolean", "then": ["element", "..."] },
"..."
],
"default": ["element", "..."]
}
}
The branches
property is an array of objects with two properties. The case
property takes the input values as variables and returns a boolean value. If it is true, the elements in the then
property are used.
The first condition that evaluates to true is the one that is used. If no case
evaluates to true, the elements in default
are used.
expry([
// ...
{
$schema$switch: {
branches: [
{
case: "$$softwareDeveloper",
then: [
// ...
],
},
{
case: { $not: "$$softwareDeveloper" },
then: [
// ...
],
},
],
default: [],
},
},
]);