Restrict the response base on a possible empty question (the answer for this question might be empty)

Hi team,
I’m building a form building the validation criteria function that I want to make date B should be later than date A. But in my data sometimes date A is missing, so date B can not entry?. How could I solve this problem?

Thank you all

Hi @manh_nguyen,

How about creating a dummy calculation? For example; in case of A is missing select today() as a milestone so B should always be later than today?

The above option could be changed according to your needs.

1 Like

@manh_nguyen, you should be able to do it as outlined in the image shared below:

In the survey tab of your XLSForm:

Data entry as seen in Enketo: when date 2 is smaller than date 1

Data entry as seen in Enketo: when date 2 is equal to date 1

Data entry as seen in Enketo: when date 2 is greater than date 1

Reference XLSForm:

Constraint Date.xlsx (9.7 KB)

1 Like

Hi @Kal_Lam, How about date1 is empty but i still want to enter date 2?
For example in my data the first test date is missing but I already set the constraint for the second test date that should be later than first test date. It will show the message as below. the think that i want is still enter the date for second test even thought the first test date is empty

Hi @manh_nguyen,

That’s why Kal provided an if statement in the constraint saying:
IF Date 1 NOT EQUALS to EMPTY VALUE then DATE2 should be bigger than DATE1

1 Like

In my example, some records has the value for date 1 and some don’t. In Kal’s example, date 1 is required. What should i change in the If function that if date 1 is not equal to empty date 2 should be greater than date 1 and if date 1 equal to empty date 2 should later a certain date (example 2022-05-30)?

if(${date1} != β€˜β€™, .>${date1}, . >= date(β€˜2021-04-01’) and . <= date(β€˜2021-10-01’))
thank you i found my solution

2 Likes

Hi @hakan_cetinkaya, I used the syntax above but when i deployed my form, it automatically change from this
if(${date1} != β€˜β€™, .>${date1}, . >= date(β€˜2021-04-01’) and . <= date(β€˜2021-10-01’)) to this
. >= date(β€˜2021-04-01’) and . <= date(β€˜2021-10-01’) only and the if statement disappeared.
Do you know what happened?

Hi @manh_nguyen,

Where did you use that syntax, can you show a screenshot?

1 Like


thanks @hakan_cetinkaya I used it here but after i deployed the form and back to edit form it show like this again


I also try in the excel form but it again if i upload the form, deployed it, it will automatic changed to
. >= date(β€˜2021-04-01’) and . <= date(β€˜2021-10-01’)

@manh_nguyen, try this it should work …

if(${date1} != '', .>${date1}, (. >= date(β€˜2022-06-01’) and . <= date(β€˜2022-06-30’)))

Reference XLSForm:

Constraint Date.xlsx (9.7 KB)

1 Like

it works perfectly. Thank you very much @Kal_Lam

1 Like