Multiple comparison in constraint

Using XLSForm,
I'm trying to constrain the upper and lower bounds of an integer.

I have tried:

20 <= . <= 200

This produces no error at conversion time, but the constraint doesn't work in the form. (The field accepts any value.)

. >= 20 and . <= 200
(. >= 20) and (. <= 200)

These both produce an error at conversion time:

org.javarosa.xform.parse.XFormParseException: bind for ${diastolic_bp} contains invalid constraint expression [. >= 20 and <= 200] Bad node: org.javarosa.xpath.parser.ast.ASTNodeAbstractExpr@7fbe847c
----
org.javarosa.xform.parse.XFormParseException: bind for ${diastolic_bp} contains invalid constraint expression [(. >= 20) and (<= 200)] Bad node: org.javarosa.xpath.parser.ast.ASTNodeAbstractExpr@7fbe847c

PS: I'm aware I could use a range widget for this purpose. But the form is just an example I'm working on for illustrating constraints. So it would be good to know why this isn't working.

Hi Adam,

How about :
((. > 20) or (. = 20)) and ((. < 200) or (. = 200))
or possibly the following - give you said this is integer arithmetic
(. > 19) or (. < 201)

Hi Adam,

Could you send an example of the form? I can't reproduce the errors when converting (I am using the offline converter of XLSForms)

UGH

I just realized I HAD A TYPO.

I missed the dot on the second comparison.
(It was correct in my explanation above, but you can see it is missing in the error message. That's how I actually had it in my form.)

This works just fine, as expected:

. >= 20 and . <= 200

Thanks, all.

2 Likes