I’m currently trying to implement in one of our template a checkbox that will be automatically ticked under certain conditions (See below my current coding)
{% if company.company_form == “sa” or company.company_form == “sca” or company.company_form contains ‘commandite par actions’ or company.company_form contains ‘anonyme’%}
{% assign custom.is.optioncapital == true %}
{% else %}
{% assign custom.is.optioncapital == false %}
*NB: I’m only a rookie in the liquid world so don’t be hard with my initial coding
However, while using such code the checkbox remain unticked even if the company form criteria is true.
Thank you for reaching out! Input variables can never be filled by an assign statement. This statement is exclusively designed for local variables.
Instead, consider leveraging this condition to establish a default value for your input. Remark that default values are not stored in the database though!
Your code could look like this:
{% if company.company_form == “sa” or company.company_form == “sca” or company.company_form contains ‘commandite par actions’ or company.company_form contains "anonyme" %}
{% assign default_optioncapital == true %}
{% else %}
{% assign default_optioncapital == false %}
{% endif %}
{% input custom.is.optioncapital as:boolean default:default_optioncapital %}
Thanks for your advice unfortunately it does not resolve my issue and does not create an automatically checked checkbox…
I tried therefore to apply another option with a Yes/No default value that works properly (See below)
{% if company.company_form == “sa” or company.company_form == “sca” or company.company_form contains ‘commandite par actions’ or company.company_form contains ‘anonyme’%}
However, now while trying to look for the result in another template the default value shows a blank result whereas if I update manually the default selection the result return the correct value.
Do you have any view why my default value does not give the appropriate result?
the following boolean input variables will work. As mentioned previously, default values will not lead to a database entry, therefor the custom variable will still be blank. Remark that I added an assign statement within the input statement to resolve this. You can find more details on that attribute here.
{% if company.company_form == “sa” or company.company_form == “sca” or company.company_form contains ‘commandite par actions’ or company.company_form contains "anonyme" %}
{% t "capital" %} {% input custom.is.optioncapital as:boolean default:true assign:optioncapital %}
{% else %}
{% t "capital" %} {% input custom.is.optioncapital as:boolean default:false assign:optioncapital %}
{% endif %}
{% result "is_capital" optioncapital %}