Before I jump into a real eval - is there a way to express logic in
the forms?
i.e. If the contents of this field is this, go to this section.
Thank you.
Before I jump into a real eval - is there a way to express logic in
the forms?
i.e. If the contents of this field is this, go to this section.
Thank you.
yes. if you look at the demo video at
http://www.youtube.com/watch?v=lo8LaFFSkV8 you'll see examples of
logic/branching. we support full xpath expressions and they are
powerful enough to do medical protocols...
The forms can contain both Skip Logic and data constraints.
The way it's done in the XML is a section called BIND.
For every piece of data you are collection (say, question 1) there is a node
in the Instance.
*
for ever Node, there can be a BINDing (though it's not necessary).
All by itself, that doesn't do anything. But, if you want the question to be
required, this is where you add that control.
Now, let's say that you want to add a data constraint. Question 1 is this,
"What is your Age?"
You can't interview children, so the answer must be older than 18. You don't
want someone accidentally putting in the year of their birth, or some other
crazy number, so you constrain the number to be less than 100. Oh, and it
has to be a number, not a word.
*<bind nodeset="/data/question1" required="true()" constraint=". > 17 and
. < 100" * type="int" ** />
If someone puts in a crazy number for age, it won't accept it. You might
want to add an error message, so you can do that too:
*
There are lots of kinds of data constraints, you can use regular expressions
in there, like if the answer must be a 3 digit number, you can constrain
like this:
<bind nodeset="/data/question1" required="true()" type="int"
constraint="regex(., '^\d\d\d$')" jr:constraintMsg="The number must be 3
digits" />
A lot of people think these kinds of expressions are awesome, I just think
they are regular. Anyway, useful stuff.
Notice that there is a datatype constraint in there as well: *type="int"
*This will make sure only numbers (integers) can be entered and will pop up
the numerical keyboard for the user.
Other types of *types *are:
date
time
geopoint
string
there are some others, they control how the interface presents to the user.
If the *type="geopoint" *then the user will see a control to get and record
the GPS position.
Datatypes are useful in combination with Preloaders, for example, you can
record the start time of your survey (or the end time, or some other time)
like this:
That records the time that the survey starts and records it into a node
called "start".
You asked about Skip Logic as well, and you do that in the BIND also by
making use of Relevant property.
You basically add this to a question saying, THIS question should be
presented to the user IF the answer to a previous question is THAT.
Q1 asks "Do you have a dog or a cat?"
Q2 asks "What is your dog's name?"
Q3 asks "What is your cat's name?"
So, Q2 is only RELEVANT if Q1's answer is "dog". Get it?
Q3 is only RELEVANT if Q1's answer is "cat".
So, in the bind, it gets written like this:
ODK will only present the cat question to cat owners, the dog question to
dog owners.
There are multiple ways to use the RELEVANT property.
Like the Dog/Cat question above, Relevant IF some other question equals some
value.
relevant="/data/q16 = '88'"
If you want to ask ten questions about dogs and ten questions about cats,
you just give the appropriate * relevant="/data/q1= 'dog'" *to all the
dog questions and the same for the cat. So, you can skip whole sections that
way.
You can combine more than one Relevant value by putting "and" between them.
*relevant="/data/q5= '1' and /data/q6 = '88'" *
You can also use negatives, that is, Question is Relevant IF another
question's value does NOT equal something.
*relevant="/data/q5 != '0'" *
When working with multiple-select questions , where users can
select more than one answer, you can't use *node='value' *because there may
be more than one value in there. So, you can use *selected(node, 'value')
*
*relevant="selected(/data/q11, '88')" *
Yes, it can be combined with other Relevants for other nodes
You can even say THIS question is Relevant only IF the multiple choice
question does NOT have a certain value selected.
relevant="not(selected(/data/q11, '0'))"
OK, that's what I have to say about that. I write a lot of skip logic and
data constraints, so I have figured out some tricks. Also some caveats, like
the ODK Form Validator (though it is awesome, all praise to the mighty
Validator) does not get all mistakes in the BIND.
If you are writing some BIND statements, and you refer to a non-existent
node (like you mix up the letter 'O' and the number '0' or something like
that, you have a node called /data/O01, but you spell it /data/OO1) the
validator will not catch it, but your form will crash like a lead balloon.
You can watch it crash with the adb logcat, and you will see an error
message "Node does not exist".
Good luck with your stuff, m0j0 OUT!
☞§※⌘:airplane:
~Neil
On Wed, Oct 13, 2010 at 7:39 PM, Frank R frankruss.ny@gmail.com wrote:
Before I jump into a real eval - is there a way to express logic in
the forms?i.e. If the contents of this field is this, go to this section.
Thank you.
--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.comopendatakit%2Bunsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en
this is too good to stay on the mailing list. i've added it to
http://code.google.com/p/opendatakit/wiki/XFormLogicExplained
Wow. I think we have a winner for: greatest response Ever in any
forum Ever. Thank you so much.
Frank
that's the nicest thing anyone has said to me all day.
☞§※⌘:airplane:
~Neil
Wow. I think we have a winner for: greatest response Ever in any
forum Ever. Thank you so much.Frank
You earned it, brother. That was the most helpful post I've ever seen in
my entire life. Thank you for the
random act of kindness - and great generosity with your time.
On Fri, Oct 15, 2010 at 2:38 PM, Neil Hendrick mojotexas@gmail.com wrote:
that's the nicest thing anyone has said to me all day.
☞§※⌘:airplane:
~NeilOn Fri, Oct 15, 2010 at 1:46 AM, Frank R frankruss.ny@gmail.com wrote:
Wow. I think we have a winner for: greatest response Ever in any
forum Ever. Thank you so much.Frank
--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.comopendatakit%2Bunsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en
Hi, I am both very new to ODK and programming in general. I am
attempting to program data validation using answers from previous
questions.
Using the above post as my guide, here is my current, yet wrong,
attempt:
I keep getting the following error: Invalid XPath expression [. <= 13
& HouseholdSurvey/HouseholdMember/Relation . = 2]!
Does anyone have any suggestions on how to fix the error?
It looks like you have an extra "." just before the equals of the second
part of the constraint ( .../Relation . = 2).
I think you wanted
<bind nodeset="/HouseholdSurvey/
On Tue, Nov 16, 2010 at 9:12 AM, Ulli unischan@gmail.com wrote:
Hi, I am both very new to ODK and programming in general. I am
attempting to program data validation using answers from previous
questions.
Using the above post as my guide, here is my current, yet wrong,
attempt:I keep getting the following error: Invalid XPath expression [. <= 13
& HouseholdSurvey/HouseholdMember/Relation . = 2]!Does anyone have any suggestions on how to fix the error?
On Oct 15, 1:57 pm, Frank Russ frankruss...@gmail.com wrote:
You earned it, brother. That was the most helpful post I've ever seen
in
my entire life. Thank you for the
random act of kindness - and great generosity with your time.
On Fri, Oct 15, 2010 at 2:38 PM, Neil Hendrick mojote...@gmail.com wrote:
that's the nicest thing anyone has said to me all day.
☞§※⌘:airplane:
~NeilOn Fri, Oct 15, 2010 at 1:46 AM, Frank R frankruss...@gmail.com wrote:
Wow. I think we have a winner for: greatest response Ever in any
forum Ever. Thank you so much.Frank
--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.comopendatakit%2Bunsubscribe@googlegroups.com
<opendatakit%2Bunsubscribe@googlegr oups.com>
Options:http://groups.google.com/group/opendatakit?hl=en--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.comopendatakit%2Bunsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en
--
Mitch Sundt
Software Engineer
http://www.OpenDataKit.org
University of Washington
mitchellsundt@gmail.com
Thank you, but I am still getting the same error.
Use AND in place of &
Thank you, but I am still getting the same error.
It looks like you have an extra "." just before the equals of the second
part of the constraint ( .../Relation . = 2).
I think you wanted<bind nodeset="/HouseholdSurvey/
HouseholdMember/Age" required="true()"
constraint= ". <= 13 & HouseholdSurvey/HouseholdMember/
Relation = 2" jr:constraintMsg="Respondent too young to be
married." />
Hi, I am both very new to ODK and programming in general. I am
attempting to program data validation using answers from previous
questions.
Using the above post as my guide, here is my current, yet wrong,
attempt:I keep getting the following error: Invalid XPath expression [. <= 13
& HouseholdSurvey/HouseholdMember/Relation . = 2]!Does anyone have any suggestions on how to fix the error?
You earned it, brother. That was the most helpful post I've ever
seen
No dice...
can you send dpaste.com the form and send me (or the list) a link?
Here goes: http://dpaste.com/276126/
Thank you for taking a look.
You will need a / before householdsurvey ie < ;=13 and
/Householdsurvey/.....
Here goes: http://dpaste.com/276126/
Thank you for taking a look.
On Nov 16, 3:03 pm, Yaw Anokwa yano...@gmail.com wrote:
can you send dpaste.com the form and s...
On Tue, Nov 16, 2010 at 12:02, Ulli unisc...@gmail.com wrote:
No dice...
On Nov 16, 2:...
Still getting the error.
http://dpaste.com/276412/ works for me. try it.