CASE: make an input required

This case should’ve been made as soon as this functionality became available, but better late then never, I guess :blush:

It is now possible to have an input (almost any database variable) be required to fill in.

Let’s take this example, where we didn’t have a better solution then to mis-use indicators for it:
Screenshot 2020-02-21 at 13.35.34

Some extra coding we have to do to get this:

{% comment %}create string for all possible sectors{% endcomment %}
{% assign array_sectors = "Metal|IT|Catery|Cars" %}

{% comment %}make the select dropdown obligated to pick a value{% endcomment %}
{% if company.custom.info_company.sector != blank %}
  {% assign ind_sector = 0 %}
{% else %}
  {% assign ind_sector = 1 %}
{% endif %}

{% stripnewlines %}
|----15%----
|----05%----
|----10%----
|-----------+
{% newline %}
| {% t "Sector of the company:" %}
| {% if ind_sector != 0 %}
    {% unreconciled ind_sector as:indicator unreconciled_text:"A value needs to be selected" %}
  {% endif %}
| {% input company.custom.info_company.sector as:select options:array_sectors %}
|  
{% endstripnewlines %} 

But look at this now:
Screenshot 2020-02-21 at 13.36.57

Isn’t this way nicer? :smirk:

By adding the required attribute to the coding of your database variable, you are able to have this:

required:true

like this for example:

{% input company.custom.info_company.sector as:select options:array_sectors required:true %} 

:bulb: You could even have the required attribute depend on another database variable for example (if that value gets assigned beng true or false, like a boolean is!):

{% ic %}{::infotext}
Are the following checks required? {% input custom.all_checks.requirement as:boolean %}
{:/infotext}{% endic %}

{% comment %}assign to a variable{% endcomment %}
{% assign checks_choice = custom.all_checks.requirement %}

<br>

{% comment %}new one{% endcomment %}
{% stripnewlines %}
|----15%----
|----10%----
|-----------+
{% newline %}
| {% t "Sector of the company:" %}
| {% input company.custom.info_company.sector as:select options:array_sectors required:checks_choice %}
| &nbsp;
{% endstripnewlines %} 

Let’s tweak this case for instance, and tweak it to become like this (with Y or N options instead of just a boolean):

Here’s the code:

{% assign array_checks = "Has every invoice been delivered by the customer?;Are the sales invoices been booked and finalized?;Are the purchase voices been booked and finalized?;Are there any invoices that are related to a previous VAT-period?" | split:";" %}

{% assign array_keys = "delivered;sales_finalized;purchases_finalized;previous_vat" | split:";" %}


<!---------- actual template ----------> 

<br>

{% stripnewlines %}
|
| {% t "VAT-check" %}
| {% t "Extra comments" %}
{% newline %}
|----5%----
|----35%---
|----------+
{% for check in array_keys %}
{% newline %}
| {% input custom.[check].check_mark as:select options:"Y|N" required:true %}
| {{ array_checks[forloop.index0] }} 
| {% input custom.[check].extra_info as:text size:mini placeholder:"Extra info" %}
{% endfor %}
{% endstripnewlines %} 

You’ll have a lot of possibilities now, and some minor work to tweak existing templates :wink:

:exclamation: PS when you use defaults, be sure to never use the required attribute; it makes no sense doing that, as your input will always have a value (because of the default) !