You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Patrick Refondini <pa...@pobox.com> on 2006/06/01 00:47:37 UTC

Re: CFORMS: Accept Multiple Date Formats

Daniel Curran wrote:
> I have a date field in my form definition setup as:
> 
> <fd:field id="dscdate">
>  <fd:datatype base="date">
>    <fd:convertor type="formatting">
>      <fd:patterns>
>        <fd:pattern>MM-dd-yyyy</fd:pattern>
>        <fd:pattern>MM/dd/yyyy</fd:pattern>
>      </fd:patterns>
>    </fd:datatype>
> </fd:field>
> 
> When a user enters a date such as 10-20-2005 a failure is the result, 
> with the form generating a validation message. When entering the date as 
> 10/20/2005 the submission is successful. Is it possible to accept both 
> these formats? If so how should this be setup?
> 
> Thanks,
> Dan

Hi Daniel,
The only way I know to have "multiple" patterns is with locale:

<fd:convertor type="formatting">
   <fd:patterns>
     <fd:pattern>MM/dd/yyyy</fd:pattern>
     <fd:pattern locale="nl-BE">dd/MM/yyyy</fd:pattern>
     <fd:pattern locale="fr">dd-MM-yyyy</fd:pattern>
   </fd:patterns>
</fd:convertor>

Example taken from:
http://cocoon.apache.org/2.1/userdocs/widgetconcepts/datatypes.html

But this won't allow two "active" patterns at the same time which seems 
to be what you're after.

You might also consider using aggregated fields, see (click "switch" 
button):
http://cocoon.zones.apache.org/demos/release/samples/blocks/forms/aggregate/example

Just hints,

Patrick

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CFORMS: Accept Multiple Date Formats

Posted by Kris Schneider <ks...@gmail.com>.
On 5/31/06, Patrick Refondini <pa...@pobox.com> wrote:
> Daniel Curran wrote:
> > I have a date field in my form definition setup as:
> >
> > <fd:field id="dscdate">
> >  <fd:datatype base="date">
> >    <fd:convertor type="formatting">
> >      <fd:patterns>
> >        <fd:pattern>MM-dd-yyyy</fd:pattern>
> >        <fd:pattern>MM/dd/yyyy</fd:pattern>
> >      </fd:patterns>
> >    </fd:datatype>
> > </fd:field>
> >
> > When a user enters a date such as 10-20-2005 a failure is the result,
> > with the form generating a validation message. When entering the date as
> > 10/20/2005 the submission is successful. Is it possible to accept both
> > these formats? If so how should this be setup?
> >
> > Thanks,
> > Dan
>
> Hi Daniel,
> The only way I know to have "multiple" patterns is with locale:
>
> <fd:convertor type="formatting">
>    <fd:patterns>
>      <fd:pattern>MM/dd/yyyy</fd:pattern>
>      <fd:pattern locale="nl-BE">dd/MM/yyyy</fd:pattern>
>      <fd:pattern locale="fr">dd-MM-yyyy</fd:pattern>
>    </fd:patterns>
> </fd:convertor>
>
> Example taken from:
> http://cocoon.apache.org/2.1/userdocs/widgetconcepts/datatypes.html
>
> But this won't allow two "active" patterns at the same time which seems
> to be what you're after.

Right, it looks like a custom
FormattingDateConvertorBuilder/FormattingDateConvertor would be
needed. The standard builder just calls:

convertor.setNonLocalizedPattern(pattern)

If there's no locale provided for a pattern. So, you'd need a
builder/convertor that would do something like this instead:

convertor.addNonLocalizedPattern(pattern) // new convertor method

The convertor would then have to cycle through the non-localized
patterns and use the first one that formats/parses without an error.

> You might also consider using aggregated fields, see (click "switch"
> button):
> http://cocoon.zones.apache.org/demos/release/samples/blocks/forms/aggregate/example
>
> Just hints,
>
> Patrick

-- 
Kris Schneider <ma...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org