# CASE: make an input required

**URL:** <https://community.silverfin.com/t/case-make-an-input-required/1680>\
**Category:** Cases\
**Tags:** mandatory, required\
**Created:** [February 21, 2020, 12:54pm UTC](https://community.silverfin.com/t/case-make-an-input-required/1680 "2020-02-21T12:54:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [February 21, 2020, 12:54pm UTC](https://community.silverfin.com/t/case-make-an-input-required/1680/1 "2020-02-21T12:54:31Z")

</div>

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

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](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/2X/0/0974bf43758ba04ad148bfced7dd0b9af926a0f9.png)

Some extra coding we have to do to get this:

```auto
{% 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 %}
| &nbsp;
{% endstripnewlines %} 

```

But look at this now:  
 ![Screenshot 2020-02-21 at 13.36.57](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/2X/3/3eaba5d0f458716fbfb9ce66ce8e852a2ba3e196.png)

Isn’t this way nicer? 😏

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

```auto
required:true

```

like this for example:

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

```

💡 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!):

```auto
{% 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](https://community.silverfin.com/t/case-array-of-questions-with-checks/863) for instance, and tweak it to become like this (with Y or N options instead of just a boolean):

 ![Screenshot 2020-02-21 at 13.45.05](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/2X/e/e1ab65b1b961b0cc2536f9d26dd76556ca251ea4.png)

Here’s the code:

```auto
{% 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 😉

❗ 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) !
