Constraint on an integer field works when using a web browser but not when using the Survey123 mobile app

1350
3
Jump to solution
11-22-2023 09:56 AM
OregonStateMarineBoard
New Contributor

Hello,

I'm trying to establish a constraint in Survey123 to restrict the allowable values in an integer field to only allow multiples of 0.25. The purpose of the field is for users to enter how much time they spent on an activity and we want it to be in 15 minute increments. I was able to get some different expressions to work on a browser but none of them worked using the survey123 app. Using a constraint would prevent any and all values from being accepted in the mobile app. Any value entered would result in a constraint violation in the survey123 mobile app.

Here are some of the different options I tried:

1) .25 * round(${mpHOURS} * 4) = ${mpHOURS}

2) (${mpHOURS}*4 - floor(${mpHOURS}*4)) = 0

3) regex(string(${mpHOURS}), '^\d+ (\.00|\.25|\.50|\.75)?$')

4) Javascript function

function isMultipleOfQuarter(value) {

var multiplied = value * 4;

return multiplied ===

Math.floor(multiplied);}

Additional Information:

Field type is decimal

published in Survey123 Connect version 3.18.123

Thank you!

 

 

0 Kudos
1 Solution

Accepted Solutions
OregonStateMarineBoard
New Contributor

*UPDATE* I added some additional constraints to be a value between 0 and 24 and added the 15 minute interval as a modulo operation and the constraint seems to be working now in browsers and mobile apps.

. and ${TimeField} <=24 and ${TimeField} >= 0 and (${TimeField} *100) mod 25 = 0

View solution in original post

3 Replies
abureaux
MVP Frequent Contributor

Not the best at JS, but this should work:

function isMultipleOfQuarter(var1) {
    var var1 = var1/0.25;

    var1 = var1 - Math.floor(var1)

    return var1;
}

 

Not a multiple of 0.25:
abureaux_0-1700679017086.png

Multiple of 0.25:
abureaux_1-1700679038799.png

 

DougBrowning
MVP Esteemed Contributor

First thing I always check on these is the bind::type column.  Make sure to set that or it can be treated as string.

OregonStateMarineBoard
New Contributor

*UPDATE* I added some additional constraints to be a value between 0 and 24 and added the 15 minute interval as a modulo operation and the constraint seems to be working now in browsers and mobile apps.

. and ${TimeField} <=24 and ${TimeField} >= 0 and (${TimeField} *100) mod 25 = 0