Recommended Way To Handle Non-ISO Date Formats

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Recommended Way To Handle Non-ISO Date Formats

Kaex
Hi all,

Unfortunately, I've run into an issue while trying to send my form instance to a third party service provider.  They insist on not taking ISO formatted (yyyy-mm-dd) dates, but instead expect dates to be in US format (mm/dd/yyyy).  :(

What is the recommended approach for handling this in Orbeon?  So far I have the following binds that *almost* work:

<xforms:bind id="applicant-dob-bind" nodeset="instance('iso-dates')/dob"
                  type="xforms:date"
                  constraint="if(. != '')
                  then
                      (xs:date(.) le current-date())
                  else
                      true()"  
                 
                  xxforms:default="if (string-length(instance('fr-form-instance')/dob) gt 0)
                  then
                     (xs:date(.....Nasty substring code to change to ISO format.....))  
                  else
                      xxforms:get-request-attribute('applicantDob', 'text/plain')"/>

<xforms:bind nodeset="PersonalDetails/DateOfBirth"
                  calculate="format-date(instance('non-iso-dates')/dob, '[M01]/[D01]/[Y]')" />
               
Reply | Threaded
Open this post in threaded view
|

Re: Recommended Way To Handle Non-ISO Date Formats

Kaex
Oops, typo in the above code, it should be:

<xforms:bind id="applicant-dob-bind" nodeset="instance('iso-dates')/dob"
                  type="xforms:date"
                  constraint="if(. != '')
                  then
                      (xs:date(.) le current-date())
                  else
                      true()"  
                 
                  xxforms:default="if (string-length(instance('fr-form-instance')/dob) gt 0)
                  then
                     (xs:date(.....Nasty substring code to change to ISO format.....))  
                  else
                      xxforms:get-request-attribute('applicantDob', 'text/plain')"/>

<xforms:bind nodeset="PersonalDetails/DateOfBirth"
                  calculate="format-date(instance('iso-dates')/dob, '[M01]/[D01]/[Y]')" />

I should also mention that the above is giving me an "Invalid date "04/13/2011" (When year exceeds 4 digits, leading zeroes are not allowed) (org.orbeon.saxon.type.ValidationException)" error when the value is changed.
Reply | Threaded
Open this post in threaded view
|

Re: Recommended Way To Handle Non-ISO Date Formats

Kaex
Never mind, I had a stray "xform-value-changed" listener from an earlier attempt.  

I remove that and everything works fine.  I'm still interested in any better ways to accomplish this though.
Reply | Threaded
Open this post in threaded view
|

Re: Re: Recommended Way To Handle Non-ISO Date Formats

Tambet Matiisen
It seems, that you are basically doing right thing, but I didn't
understand why you need all that constraint and default code in first
bind. In my opinion you just need 2 instances:
1) the first one is used for entering data. This is where data type is
date, to render the date control on input form.
2) the second one is used for sending data to external service. In this
instance the data type is string for the same element and you can
calculate it from the first instance using bind rule similar to the last
one of yours. You can copy other elements with calculate rule as well.

Actually, if your form has many fields and repeats, then having two
instances and copying data between them might complicate the process too
much. So you could also put the second field into the same instance and
enable it only during submission. The code could be something like this:

<xforms:instance>
<data>
     ...
<PersonalDetails>
<DateOfBirth>1976-05-12</DateOfBirth>
<DateOfBirth>05/12/1976</DateOfBirth>
</PersonalDetails>
     ...
</data>
</xforms:instance>

<xforms:instance id="control">
<data>
<submitting>false</submitting>
</data>
</xforms:instance>

<xforms:bind nodeset="PersonalDetails/DateOfBirth[1]" type="xforms:date"
relevant="not(boolean-from-string(instance('control')/submitting))"/>

<xforms:bind nodeset="PersonalDetails/DateOfBirth[2]"
type="xforms:string"
relevant="boolean-from-string(instance('control')/submitting)"
calculate="format-date(../DateOfBirth[1],
'[M01]/[D01]/[Y]')"/>

<xforms:submission action="..." ...>
<xforms:setvalue ref="instance('control')/submission" value="'true'"
events:event="xforms-submit"/>
<xforms:setvalue ref="instance('control')/submission" value="'false'"
events:event="xforms-submit-done"/>
<xforms:setvalue ref="instance('control')/submission" value="'false'"
events:event="xforms-submit-error"/>
</xforms:submission>

   Tambet

On 23.02.2012 5:03, Kaex wrote:
> Never mind, I had a stray "xform-value-changed" listener from an earlier
> attempt.
>
> I remove that and everything works fine.  I'm still interested in any better
> ways to accomplish this though.
>
> --
> View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/Recommended-Way-To-Handle-Non-ISO-Date-Formats-tp4410775p4410826.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws