Skip if previous question is blank

Hi everyone,

How do I write the relevant code to skip a question if previous question
(wish is text) is blank?

Tnx

1 Like

Try

<bind ... relevant="/model/path/to/antecedent = '' ">

or

<bind ... relevant="string-length(/model/path/to/antecedent) = 0" >

You need to perform the dependency test in the binding for your dependent
data model element, against the data model element corresponding to your
antecendent. You dont perform relevancy tests against the 'previous' form
question per se.

  • Gareth
ยทยทยท On Sunday, May 7, 2017 at 8:19:00 PM UTC+12, Roque Covane wrote: > > Hi everyone, > > How do I write the relevant code to skip a question if previous question > (wish is text) is blank? >

And to build on Gareth's great response, if you are using XLSForm,
http://xlsform.org/#relevant might be of help.

Yaw

ยทยทยท On Sun, May 7, 2017 at 8:30 PM, wrote: > On Sunday, May 7, 2017 at 8:19:00 PM UTC+12, Roque Covane wrote: >> >> Hi everyone, >> >> How do I write the relevant code to skip a question if previous question >> (wish is text) is blank? > > > Try > > > > or > > > > You need to perform the dependency test in the binding for your dependent > data model element, against the data model element corresponding to your > antecendent. You dont perform relevancy tests against the 'previous' form > question per se. > > - Gareth > > -- > -- > 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/d/optout.

Thanks Yan for your support

Thanks Xiphware for your support

I came across this post whilst looking for something more general about hiding / skipping questions. The solution from @Xiphware is useful and, slightly adapted, works for other data types (i.e. not just strings), which might be helpful to others, hence sharing it.

In my case I want to geolocate a number of images within one form that are / might be taken at different places. But if the person doesn't take an image, there's no point asking where it is, so I want to hide the geopoint question... I couldn't find anything in the documentation to help but saw this and wondered if it might work... And it does.

So basically, if the response to one question is NOT blank, you can SHOW (or hide unless answered) the relevant question simply using one of the two techniques:

in XML find the question's statement and add relevant="/model/path/to/antecedent != '' " (that's single quotes to denote 'nothing')

in XLS use the Relevant column and add ${My_Previous_Question_Name} !=''

For the record, != means 'not equal to' so the expression !='' is the same as Is Not Null / Is Not Empty

I'm only just gaining confidence to delve into XML, so having a way to include this within the XLSForm is less scary!

Presumably this would also work if you wanted to hide/show a group of questions...

Hope this helps someone out there.

3 Likes

Yup. Groups can optionally also have a relevant="..." in their binding, to show/hide the group and its entire contents. This is useful if you have a bunch of related questions (in a group) all of which become irrelevant depending on a previous response. Just hiding the entire group is a bit easier than having to setup show/hide logic for every individual dependent question.

2 Likes