Hi,
I've got a form where the users are putting in hours (Number object) and I'd like to make it so that they are only allowed to put in positive numbers. Is there a way to do this?
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Allow positive numbers only
-
- nuBuilder Team
- Posts: 508
- Joined: Fri Dec 28, 2018 1:41 pm
- Location: Krakow, Poland
- Has thanked: 10 times
- Been thanked: 18 times
Re: Allow positive numbers only
Hi,
To allow only positive values to be used like hours for example you can use select field if the range is reasonable short.
Up to one month per person it's quite easy.
For example in one application I use 2 select fields - one for hours and one for minutes with the 5 minutes step in the select object-> select tab you can place for hours:
SELECT seq,seq FROM seq_0_to_200;
and for minutes:
SELECT seq,seq FROM seq_0_to_55_step_5;
Other possibility is to check the input field value with the onblur event and automatically adjust.
for example to replace negative values with positive place the following with onblur event:
var field=this.id; $('#'+field).val(Math.abs($('#'+field).val()));
To allow only positive values to be used like hours for example you can use select field if the range is reasonable short.
Up to one month per person it's quite easy.
For example in one application I use 2 select fields - one for hours and one for minutes with the 5 minutes step in the select object-> select tab you can place for hours:
SELECT seq,seq FROM seq_0_to_200;
and for minutes:
SELECT seq,seq FROM seq_0_to_55_step_5;
Other possibility is to check the input field value with the onblur event and automatically adjust.
for example to replace negative values with positive place the following with onblur event:
var field=this.id; $('#'+field).val(Math.abs($('#'+field).val()));
You do not have the required permissions to view the files attached to this post.
If you like nuBuilder, please leave a review on SourceForge
Re: Allow positive numbers only
Martin,
You could put this code on the onchange event of the number field you want to validate...
Steven
You could put this code on the onchange event of the number field you want to validate...
Code: Select all
if(Number(this.value) < 0){alert('Must be a positive number...'); this.focus();}
Steven
-
- nuBuilder Team
- Posts: 4416
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 74 times
- Been thanked: 472 times
- Contact:
Re: Allow positive numbers only
You could use the HTML <input> min Attribute as described here: https://www.w3schools.com/tags/att_input_min.asp
To add this attribute to a nuBuilder object, add this JavaScript Code to your form's Custom Code field .
Simply replace the your_object_id with your nuBuilder object ID.
In addition, add a oninput event to your object's Custom Code:
To add this attribute to a nuBuilder object, add this JavaScript Code to your form's Custom Code field .
Code: Select all
if(nuFormType() == 'edit') {
$('#your_object_id').attr('min','0').attr( "step", "any" );
}
In addition, add a oninput event to your object's Custom Code:
You do not have the required permissions to view the files attached to this post.
-
- Posts: 30
- Joined: Fri Nov 09, 2018 5:42 pm
Re: Allow positive numbers only
@Janusz: Thanks! However, in my case, I need decimals.
@Steven & Kevin: I'll take a look at it. Thanks!
@Steven & Kevin: I'll take a look at it. Thanks!