Number formatting in Orbeon forms

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

Number formatting in Orbeon forms

rovsh
Hello,

We are developing forms using Orbeon. Currently we have an issue with number and date formatting according to user's locale for both input and output. Available Orbeon configuration where we can set global decimal separators, and date formatting does not fulfill our requirements. One idea is to pre- and post-process the form data. If it is a valid idea, then How can we accomplish this?
Using XPL? Where should I put and link such an XPL file so that it will hook in before and after form is shown  to user?
Is there any other way to do all of these?

Thanks a lot in advance.

-rovsh
Reply | Threaded
Open this post in threaded view
|

Re: Number formatting in Orbeon forms

Alessandro  Vernet
Administrator
Hi Rovsh,

Could you tell us more about what number/date format you need? Most likely pre/post processing that data won't be enough, as at least for the input, there is also JavaScript code that needs to be aware of the formatting.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Number formatting in Orbeon forms

rovsh
Hi Alessandro,

We have forms in Orbeon that we build using Form Builder. Later we store the source code generated by Form Builder in JSP files. These JSP files are later processed by Form Runner to produce the forms.
Each form can contain input fields for decimal numbers, and input fields for date.

The forms will be used by users from countries with different locale. For example, we have user A with locale fr_FR, and user B with locale en_GB. Both of them should be able to enter numbers into the same decimal number field according to their locale (fr_FR and en_GB have different decimal separator - fr_FR: 1.000,00 and en_GB: 1,000.00 ). Even though they enter the numbers according to their locale, we are going to store the numbers in one predefined format. And later when users open the form for Editing they should be able to see the numbers (in input fields) formatted according to their locale. The same goes for input fields for dates.
Is there any way to do all of these in Orbeon?

Thanks in advance.

-rovsh
Reply | Threaded
Open this post in threaded view
|

Re: Number formatting in Orbeon forms

Alessandro  Vernet
Administrator
Hi Rovsh,

This makes perfect sense. So it seems that you want the user's local to drive the decimal-separator and grouping-separator "parameters" of the number field. Those can be set globally with properties, in your properties-local.xml:

http://wiki.orbeon.com/forms/doc/developer-guide/xbl-components/number#TOC-Parameters

But you can also override those with attributes on fr:number. For instance: <fr:number ref="." decimal-separator="." grouping-separator=",">. Since you're producing the XForms that gets sent to Orbeon Forms, you could "decorate" the <fr:number> with the appropriate decimal and grouping separator for the current user, based on their locale.

Is this something that could work for you?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Number formatting in Orbeon forms

Alessandro  Vernet
Administrator
A couple of follow-ups:

Ideally, you should be able to override the oxf.xforms.xbl.fr.number.decimal-separator property on a per-form basis, adding xxf:xbl.fr.number.decimal-separator="…" on the first model of your page, so you wouldn't need to add a decimal-separator="…" on every fr:number in the page, but this doesn't work right now:

https://github.com/orbeon/orbeon-forms/issues/952

If performance is a concern for you, note that dynamically generating forms might hurt performance, as if the XForms code changes, the XForms engine has to redo its static analysis. For now, I wouldn't worry about it, but this is something to keep in mind.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Number formatting in Orbeon forms

rovsh
In reply to this post by Alessandro Vernet
Hi Alex,

I think the solution with "decorating" fr:number attributes will work for me. Thanks a lot!
Just one more question, Can I "decorate" fr:date-picker "format" attribute in the same way as fr:number attributes depending on the user's locale?
Because date is also different depending on user's locale.

Thanks in advance.

-rovsh


Alessandro Vernet wrote
Hi Rovsh,

This makes perfect sense. So it seems that you want the user's local to drive the decimal-separator and grouping-separator "parameters" of the number field. Those can be set globally with properties, in your properties-local.xml:

http://wiki.orbeon.com/forms/doc/developer-guide/xbl-components/number#TOC-Parameters

But you can also override those with attributes on fr:number. For instance: <fr:number ref="." decimal-separator="." grouping-separator=",">. Since you're producing the XForms that gets sent to Orbeon Forms, you could "decorate" the <fr:number> with the appropriate decimal and grouping separator for the current user, based on their locale.

Is this something that could work for you?

Alex
Reply | Threaded
Open this post in threaded view
|

Re: Number formatting in Orbeon forms

Alessandro  Vernet
Administrator
Hi Rovsh,

The date picker uses an xf:output to show the date (see first link below), so will use the format (oxf.xforms.format.output.date, see 2nd link below). You should be able to override it on a per-form basis by adding an xxf:format.output.date="…" on the first xf:model of your form.

https://github.com/orbeon/orbeon-forms/blob/master/src/resources-packaged/xbl/orbeon/date-picker/date-picker.xbl
http://wiki.orbeon.com/forms/doc/developer-guide/configuration-properties/configuration-properties-xforms#TOC-For-xforms:output-

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet