I don't want that it is possible to fill in negative numbers in mine inputfield?

I have several inputfields and it is possible to fill in negative numbers I only want 0 and above how can I fix this?

Hi! 

Have you tried a mask ?


In the forge you find  several , this is one :

https://www.outsystems.com/forge/component-overview/647/custom-input-masks

Regards

Graça


Solution

Hi Halit,


this is a example:

Please set the below script in text box's Extended Properties or see below snap shot.

SyntaxEditor Code Snippet

onkeypress

SyntaxEditor Code Snippet

"return (event.charCode == 8 || event.charCode == 0 || event.charCode == 13) ? null : event.charCode >= 48 && event.charCode <= 57"


Cheers,
Nuno Verdasca


Solution

Hi Halit,

Try with min = 0 on extended properties. If the input is mandatory and you have client validation, it will be impossible to submit negative numbers.

Regards

Halit,


I believe that you have a couple of solutions. Some of them already well explained here in this post.


1- Accept negative inputs in your input field and allow the user to submit those values. Using a server side validation you will check if the input is higher than zero. If the value is lower than zero you can display a message to your end user saying that the value needs to be higher than zero. Otherwise you can save the data.


2- Other nice behaviour, like Maria da Graça Peixoto said, is to use a mask. Using a mask you can easily share, in real time, what is expected from that inputfield. 


3- Using javascript, like Nuno's example. You cannot type negative values that way. However, you can still reach negative values if you use the up and down arrows in the input. A combination of Nuno's and Bruno's solution works nice.


4- Or, less efficient, to have an on change action associated with your input that will check if the value is lower than zero. If it's the case you make an assign where you return the value zero to your variable.


You have plenty of options.


Best regards,


João Delgado



Hello, you have many options to solve this, you can use the "CurrencyInput" component and set the 'allowMinus' property to false.

Or you can use other options with javascripts..

Thank you all for youre time and ideas! 

Halit Ozdogru wrote:

Thank you all for youre time and ideas! 

It's always nice to see the community wanting to help each other and share ideas so that we can all grow together.