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
answers if previous answer = no.

Mitch gave me the answer

"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
non-zero-length answer, otherwise, we have a zero-length answer"

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)
to indicate 'not answered'.
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
answers if previous answer = no.

Mitch gave me the answer

"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
non-zero-length answer, otherwise, we have a zero-length answer"

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!

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


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
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com