Problem with constraint on date widget

What is the problem? Please be detailed.
I want to add a FullDate question in my form, with constraint for valid date btw 2 dates(selected in the form).The form is created and loaded from my app, however the validation for the date never pass, no mather which date I'm selecting.
I have tested with last version of Collect app and is the same.
After deep debugging I have reached the point in JavaRosa library validation, where the lib expects the comparison date as double and when I checked in the form is a string. Here is an example from my form :
<bind nodeset="/data/select_date" type="date" constraint="(. &gt;= '2018-01-01') and (. &lt;= '2018-03-31')" jr:constraintMsg="jr:itext('/data/select_date:constraintMsg')"/>

Then I see in the lib that this Date as double is "The number of days (as a double precision floating point) since the Epoch"

I have manually changed the date and works, but for the clients will be hard to calculate the dates for it.

Thanks in advance!

What ODK tool and version are you using? And on what device and operating system version?
to create the form :
to test the form : Collect v1.12.2, Android v8.1.0, device used... Nexus x5

What steps can we take to reproduce the problem?
I will attach the original form to test with

What you have you tried to fix the problem?
When I replaced the strings with numbers it works as expected :
<bind nodeset="/data/select_date" type="date" constraint="(. &gt;= 17532.0) and (. &lt; 17621.0)" jr:constraintMsg="jr:itext('/data/select_date:constraintMsg')"/>

Anything else we should know or have? If you have a test form or screenshots or logs, attach here.
Sorry I can't attach a file

Hi @2math,

Sorry you couldn't upload your form! It might have helped to see the problem.

Are you saying that:

  1. a first date is entered
  2. a second date is entered
  3. a third date is entered that must have a constraint that it is BETWEEN date 1 and date 2?

Thanks for your help clarifying,

Hi @janna,

No is just 1 date, which should be selected in the calendar and have to be btw 2018-01-01 and 2018-03-31 . I can select the date, but can't go to next question, because the validation can't pass and the app shows the Constraint message.

I'm useing the web tool and it looks like the XFrom created with it has invalid data, because the dates for validations should be numbers instead of strings.
Here is from the web tool :
<bind nodeset="/data/select_date" type="date" constraint="(. &gt;= '2018-01-01') and (. &lt; '2018-03-31')" jr:constraintMsg="jr:itext('/data/select_date:constraintMsg')"/>
and never passes the validation.
After manually changed with this :
<bind nodeset="/data/select_date" type="date" constraint="(. &gt;= 17532.0) and (. &lt; 17621.0)" jr:constraintMsg="jr:itext('/data/select_date:constraintMsg')"/>
It works

Okay, so on the ODK build site, what did you enter into the constraint box?

I just entered (. <= 17621) and (. >= 17532) and it looks like it came up correctly in the xml form.

But not sure if I've been able to replicate what you've done.

Thanks for further clarification!

On the ODK build site, I click on the constraint field and a calendar appear, then I select a date and it fills the input field with date formated as yyyy-MM-dd (2018-01-01)
Then in the XForm xml file I can see that this constrain is btw '' and javarosa parse it as a text.
How were you able to enter (. <= 17621) and (. >= 17532)?
I tried to set the numbers manually, but I see in the form that is still parsed as text but not number. Even so tested and not passing the validation :frowning:

Hi @janna,
Here is a video with my screen capture :

direct download :

Okay yes I see what is happening.

Do not select the dates by using the "Range".

Instead, go to the bottom of the right hand side column, and you'll see something that says "Advanced" with an arrow beside it. Click on the arrow, and a "constraint" box will appear. In the constraint box, type:
(. <= 17621) and (. >= 17532)

I hope that works for you!

How did you upload the screen capture to your reply? Is that uploading a gif? Or another way? That was great so I could see what you were doing! If I knew how to do that I'd send you a screen capture too :slight_smile:


OK I see.
The question is that for clients using this form will be hard to calculate that 01/01/2018 is 17621 days after 1900 year. My client says that if this option is available(to select dates as constrains) then must work and the problem is in my application :frowning:
Probably this Range option should be hidden for date questions?

As for the video, I have uploaded it to dropbox and made a shared link with it, then just pasted the link here. You have to change the 0 on the back of link to 1 for direct download.

Thanks for your help, @janna !

This looks like a bug in Build! The output should be constraint="(. &gt;= date('2018-01-01')) and (. &lt;= date('2018-03-31'))"

For now you can use the advanced constraint box as @janna suggested to write out the constraint yourself with the date calls. I've filed an issue at

1 Like