If staments

Hi guys are there if statements for validations in the forms?

i can see there are if statements here
http://opendatakit.org/help/form-design/binding/

but the problem is knowing which fields am i to put the condition and other
values

··· On Wednesday, May 8, 2013 12:28:43 PM UTC+2, Coulson Thabo Kgathi wrote: > > Hi guys are there if statements for validations in the forms? >

Hi Coulson,
If statements might not be necessary, often it is possible to just use a
condition formula in your constraint field.
Could you give an example of what you want your form to do when someone
uses it?
Regards,
-Nathan

··· On Wednesday, May 8, 2013 3:34:02 AM UTC-7, Coulson Thabo Kgathi wrote: > > i can see there are if statements here > http://opendatakit.org/help/form-design/binding/ > > but the problem is knowing which fields am i to put the condition and > other values > > On Wednesday, May 8, 2013 12:28:43 PM UTC+2, Coulson Thabo Kgathi wrote: >> >> Hi guys are there if statements for validations in the forms? >> >

i have a few questions, example

Q1. Primary Care giver of a child (select_one field type)

options are:

1. Mother
2.Grandmother
3. Grandfather
4. Aunt
5. Uncle

Q2. Date of birth of a mother? (field type: date)
Q3. Age of mother at delivery(in years)? (int)
Q4. Child date of birth (field type: date)

Q5. Current caregiver's age(in year)? (field type:int)

If the answer to Q1 on this form is “Mother” (answer #1) then a check
should be put in place to compare the reported age of the mother at the
time she gave birth to the child (Q#3) to the response to Q5 using the
child’s date of birth. An error flag should be given if the mother’s
current age is greater than or less than 1 year from the age of the mother
at delivery and the time interval between the date of the interview and
the child’s date of birth.

so its something like this in code:

if selected(${Q2}. 'mother') and Q4 == (mom_dob - child_dob)
pass
elseif (Q5 - Q3) <=1 and (Q6 - Q4 >=1)
print error message
else (child_dob - date_now) <=1 and (chld_dob - date_now) >= 1
print error message

You probably don't need the xpath "if" function for this, you can do it
entirely with logic formulas.
For example, here's an example of turning "if/else" logic into an "and/or"
logic formula you can put into the constraint column (assuming you're using
an XLSForm):

if A: pass
elseif B: fail
elseif C: fail
else: pass

=>

A or (not(B) and not(C))

The "if" function could be useful if you're trying to do custom error
messages because it can return text instead of true/false. If that's the
case you should put your formula in a calculation variable and reference it
in your constraint_message column. Hope this helps.
Regards,
-Nathan

··· On Friday, May 10, 2013 1:28:42 AM UTC-7, Coulson Thabo Kgathi wrote: > > i have a few questions, example > > Q1. Primary Care giver of a child (select_one field type) > > options are: > > 1. Mother > 2.Grandmother > 3. Grandfather > 4. Aunt > 5. Uncle > > > Q2. Date of birth of a mother? (field type: date) > Q3. Age of mother at delivery(in years)? (int) > Q4. Child date of birth (field type: date) > > Q5. Current caregiver's age(in year)? (field type:int) > > If the answer to Q1 on this form is “Mother” (answer #1) then a check > should be put in place to compare the reported age of the mother at the > time she gave birth to the child (Q#3) to the response to Q5 using the > child’s date of birth. An error flag should be given if the mother’s > current age is greater than or less than 1 year from the age of the mother > at delivery and the time interval between the date of the interview and > the child’s date of birth. > > so its something like this in code: > > if selected(${Q2}. 'mother') and Q4 == (mom_dob - child_dob) > pass > elseif (Q5 - Q3) <=1 and (Q6 - Q4 >=1) > print error message > else (child_dob - date_now) <=1 and (chld_dob - date_now) >= 1 > print error message > > >