# Mapped input field should only contain positive amounts

**URL:** <https://community.silverfin.com/t/mapped-input-field-should-only-contain-positive-amounts/1752>\
**Category:** Templates\
**Created:** [April 8, 2020, 1:51pm UTC](https://community.silverfin.com/t/mapped-input-field-should-only-contain-positive-amounts/1752 "2020-04-08T13:51:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbunger](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/cbunger/32/1291_2.png) [@cbunger](https://community.silverfin.com/u/cbunger)\
**Post date:** [April 8, 2020, 1:51pm UTC](https://community.silverfin.com/t/mapped-input-field-should-only-contain-positive-amounts/1752/1 "2020-04-08T13:51:42Z")

</div>

I have a template that is populated with mapped accounts. How do I make sure that my fields only contain positive amounts, i.e. if a mapped account is -X it should be displayed as X in the field. Thanks.

---

<div class="post-metadata">

**Author:** ![agustin](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/agustin/32/1207_2.png) [@agustin](https://community.silverfin.com/u/agustin)\
**Post date:** [April 8, 2020, 3:28pm UTC](https://community.silverfin.com/t/mapped-input-field-should-only-contain-positive-amounts/1752/2 "2020-04-08T15:28:52Z")

</div>

Hi @cbunger, welcome back to the Silverfin community.

So you are trying to set the value of the accounts as the default value to be shown in the inputs fields, and this values should always be positives. Am I right?

In that case and to make sure that these values are shown as absolute values, you could use the ‘abs’ filter, adding and extra step before the input field is created, like next:

> {% assign account\_abs\_value = account.value | abs %}  
> {% input custom.some.input\_field as:currency default:account\_abs\_value %}

This will make all the values taken from the accounts to be positive, but it won’t prevent the user to manually input a negative value. Which unfortunately it is not possible to limit in the input fields at the moment. Considering this situation, and if the user should not input negative values, you could display a message if they do it. For example:

> {% if custom.some.input\_field \< 0 %}  
> {% ic %}{::warningtext}Value must be positive{:/warningtext}{% endic %}  
> {% endif %}

I hope this explanation help you with you issue. If you still have any concerns, feel free to share you code here so we can take a look at that specific situation. 🙂

> **[Number](https://developer.silverfin.com/docs/number-filters#section-abs)**
>
> AbsOutputs a number into an absolute value.Input{{ -23 | abs }} This filter can also be applied with the following syntax.Input{{ ABS(-23) }} Output 23 CeilAllows to round the input UP. For example, the nearest whole number of 1.2 is 1, however, if...

Best regards,  
Agustín.

---

<div class="post-metadata">

**Author:** ![cbunger](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/cbunger/32/1291_2.png) [@cbunger](https://community.silverfin.com/u/cbunger)\
**Post date:** [April 9, 2020, 10:21am UTC](https://community.silverfin.com/t/mapped-input-field-should-only-contain-positive-amounts/1752/3 "2020-04-09T10:21:56Z")

</div>

Hi Agustin,

Thanks for your response. The fields get populated via a loop through an account array. My code looks like this:

{% assign cy\_value = period.accounts | range:column1\_account\_array[forloop.index0] %}  
{% $1+ cy\_value %}  
|]^\_ {% input custom.value.[item] default:cy\_value as:currency %} \_^[

So what I want to achieve is that the input value is positive. When I add “| abs” in the syntax line for assign cy\_value, all fields are emptied.

---

<div class="post-metadata">

**Author:** ![agustin](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/agustin/32/1207_2.png) [@agustin](https://community.silverfin.com/u/agustin)\
**Post date:** [April 9, 2020, 11:12am UTC](https://community.silverfin.com/t/mapped-input-field-should-only-contain-positive-amounts/1752/4 "2020-04-09T11:12:16Z")

</div>

Try with the next code:

> {% assign cy\_value = period.accounts | range:column1\_account\_array[forloop.index0] %}  
> {% assign cy\_value\_abs = cy\_value.value | abs %}  
> {% $1+ cy\_value %}  
> |]^\_ {% input custom.value.[item] default:cy\_value\_abs as:currency %} \_^[

So, the situation here is this. In the first line:

> {% assign cy\_value = period.accounts | range:column1\_account\_array[forloop.index0] %}

You are assigning the account drop to cy\_value (not only the value of the account).

And in the next step:

> {% assign cy\_value\_abs = cy\_value.value | abs %}

With the added “.value” you are accessing to the value information of the account, and then applying the abs filter.

In the next link is the list of all the methods you can apply to accounts (e.g. .value, .number, .count, etc.)

> **[accounts](https://developer.silverfin.com/docs/accounts)**
>
> Methods MethodReturn typeDescriptionstarredassetsliabilitiesrevenuesexpensesincomeequityaccounts dropFilters the accounts and returns a new accounts drop with only these accounts.countintegerthe amount of account drops in the accounts...

One additional thing you should consider its the line about the register: if you should use the original value or the absolute value (probably the absolute one?):

> {% $1+ cy\_value %} or {% $1+ cy\_value\_abs %}

And finally, ussing the new variable with absolute values as a default of the input:

> |]^\_ {% input custom.value.[item] default:cy\_value\_abs as:currency %} \_^[

As I commented before, you won’t be able to avoid users to manually input a negative value, and for that reason I suggested using some kind of warning or error message in that case.
