Checkbox ticked with conditions

Hi All,

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 :slight_smile:

However, while using such code the checkbox remain unticked even if the company form criteria is true.

Do you have any idea how to resolve such issue?

Thanks

Jon

Hi @JonathanK

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 %}

Have a nice day,

Michiel

Hi Michiel,

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’%}

{% t “capital” %} {% input custom.is.optioncapital as:select options:optioncapital default:“Yes” %}
{% else %}
{% t “capital” %} {% input custom.is.optioncapital as:select options:optioncapital default:“No” %}
{% endif %}

{% result ‘is_capital’ custom.is.optioncapital %}

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?

Hi @JonathanK ,

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 %}

Kind regards,
Michiel

Hi Michiel,

Many thanks for your answer I finally get your point :slight_smile: the code is working properly and resolve my issues.

Many thanks for this!

Kind regards,

Jonathan