I’m trying to validate an input value with a warning text but it’s not working correct and I think the code is correct. Does anyone know why I don’t get the results I want?
It always show me “Alles OK” even when nul is 1
{% capture myinput %}
{% input custom.test.bedrag as:currency default:0 %}
{% endcapture %}
{% if custom.test.bedrag > 0 %}{% assign nul= 1 %}{% else %}{% assign nul= 0 %}{% endif %}
nul={{ nul }}
{{ myinput }}{% if nul= 0 %}
{::infotext as="hover"} Alles OK {:/infotext}
{% else %}
{::warningtext as="hover"} Bedrag dient kleiner dan nul te zijn {:/warningtext}
{% endif %}
Your operator is typed incorrect; you should do this instead:
{{ myinput }}{% if nul == 0 %}
{::infotext as="hover"} Alles OK {:/infotext}
{% else %}
{::warningtext as="hover"} Bedrag dient kleiner dan nul te zijn {:/warningtext}
{% endif %}
So if ==
But if it’s a check that needs to make sure an input can’t be negative, I’d rather do this:
{% stripnewlines %}
| {% input custom.some.thing as:currency assign:input_var %}
{% if input_var < 0 %}
{% ic %}{::warningtext as="hover"}Cannot be negative{:/warningtext}{% endic %}
{% endif %}
{% endstripnewlines %}
Thanks Sven, that was the problem. I’am still strubling when to use of single equal sign and the double equal sign.
Your suggestions is the the one I have in mind, but I didn’t get the results I want, so I created an “Alles Ok” option to see some output, because I didn’t get any output.
Well @Peter, truth be told, I had the issue as well in the beginning…
Double operators are used to make a comparison (so one is bigger than zero eg), and the single operator is used to assign (create) a value. That’s how I remember it
Some info here and here but yeah, it’s not explicitly explained (but we’ll be sure to update that in future documentation).