# Constraint and required for integer based on previous question (instead of relevant)

Hi, I recently asked a question about how to make a string question
required if previous answer = yes and make the constraint not accept any

"You would have to have two conditions, required, and constraint
required = "selected(\${yq_q},'yes')" -- to make sure that the question
is answered if it is yes
constraint = "if( selected(\${yn_q},'yes'),string-length(.) > 0,
string-length(.) = 0)" -- if the answer is yes, we have an

Could any one tell me how to go about the same type of constraint for an
integer question? I've played around with regex but i still kind of suck.

Thanks!

The difficulty with integers is that there is no 'empty string' value for
an integer. So you would have to have some designated value (e.g., -1 or 0)
Once you designate a value, e.g., -1 as 'not answered' or 'not applicable',
then the contraint formula becomes

constraint = "if( selected(\${yn_q},'yes'), . != -1, . = -1)"

··· On Tue, Jun 18, 2013 at 8:46 AM, Bill Olander wrote:

Hi, I recently asked a question about how to make a string question
required if previous answer = yes and make the constraint not accept any

"You would have to have two conditions, required, and constraint
required = "selected(\${yq_q},'yes')" -- to make sure that the question
is answered if it is yes
constraint = "if( selected(\${yn_q},'yes'),**string-length(.) > 0,
string-length(.) = 0)" -- if the answer is yes, we have an

Could any one tell me how to go about the same type of constraint for an
integer question? I've played around with regex but i still kind of suck.

Thanks!

## --

You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an