How do I use the Catch command with formtext?


#1

Take this simple snippet. The form contains a default value of 1.

But if I delete the value, I get an error.

I want to make it in a way that, if I delete the number in the field, it will go to a default value of my choice.

In {formtext: name=hour; default=1} hour it will be
{time: h:mm a; shift=+{=hour}h}


#2

You will want to place your fallback in the location where you use the variable.

Something like this would work:

In {formtext: name=hour; default=1} hour it will be

{time: h:mm a; shift=+{=hour if hour <> "" else 1}h}


#3

Ah neat.

The function is a bit outside of my understanding. Could you maybe explain the syntax? If I can understand how it operates, I could start using it elsewhere too.

Thanks :slight_smile:


#4

The syntax for the if-else operator is

[WHEN CONDITION IS YES] if [CONDITION] else [WHEN CONDITION IS NO]

When the [CONDITION] is yes, [WHEN CONDITION IS YES] is returned, if it is no, then the [WHEN CONDITION IS NO] is returned.

Here is another example:

Number {formtext: name=number; default=100}
{="big number" if number > 10 else "small number"}
{="The number is a " & ("positive number" if number > 0 else "negative number")}


#5

Ok so basically it's

[DO THIS]
if
[THIS CONDITION IS TRUE]
else (i.e. if this condition is not true)
[DO THIS OTHER THING]

Got it. Thanks again!