Default decimal format

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

Default decimal format

MarcinKula
Hi,

I would like to set global decimal format (###,###,###,##0.00) to all my xform pages.
I've found in the documentation "Default Formatting based on properties".

Default decimal format in my properties.xml file has a proper definition.

...
<property as="xs:string" name="oxf.xforms.format.decimal"
value="if (. castable as xs:decimal) then format-number(xs:decimal(.),'###,###,###,##0.00') else ."/>
...

But it seems not to work.

I attached my simple test.
I tried to use xsd types and also types which were defined in a bind element.

It's work only when I use validate action with SetValue and directly use format-number, translate function.

My xform pages have a lot of decimal fields, that's why I want to set global decimal format
without using validate action.

How can I do it ?

I attached all my files (page-flow and xml) in a zip archive.

Thank you in advance,
Marcin.

TEST1.XHTML
-----------
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xf="http://www.w3.org/2002/xforms"
        xmlns:ev="http://www.w3.org/2001/xml-events"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:ts="http://www.test.com/TEST">
    <head>
        <xf:model id="model" schema="/apps/test/test.xsd">                               
                <xf:instance id="instance" xmlns="ts" src="input:instance"/>
                <xf:bind id="b-value1" nodeset="ts:Value1" />       
                <xf:bind id="b-value2" nodeset="ts:Value2" />       
                <xf:bind id="b-value3" nodeset="ts:Value3" type="xs:decimal" />
                <xf:bind id="b-value4" nodeset="ts:Value4" type="xs:decimal" />                                       
        </xf:model>                       
    </head>
    <body>
                                                                                                       
                <xf:input id="i-Value1" ref="ts:Value1">
                        <xf:label id="l-Value1">Value1 (xs:TValue)</xf:label>
                        <xf:alert id="a-Value1">Value1 (xs:TValue)</xf:alert>
                </xf:input>
             
                <xf:input id="i-Value2" ref="ts:Value2">
                        <xf:label id="l-Value2">Value 2 (xs:decimal)</xf:label>
                        <xf:alert id="a-Value2">Value 2 (xs:decimal)</xf:alert>
                </xf:input>
             
                <xf:input id="i-Value3" ref="ts:Value3">
                        <xf:label id="l-Value3">Value 3 (bind xs:decimal)</xf:label>
                        <xf:alert id="a-Value3">Value 3 (bind xs:decimal)</xf:alert>
                </xf:input>
             
                                                <xf:input id="i-Value4" ref="ts:Value4">
                        <xf:label id="l-Value4">Value 4 (bind xs:decimal with action)</xf:label>
                        <xf:alert id="a-Value4">Value 4 (bind xs:decimal with action)</xf:alert>
                        <xf:action ev:event="xforms-value-changed">
                                <xf:setvalue ref="." value="for $Value in format-number(number(translate(.,',','.')),'#.00') return if ($Value != 'NaN') then $Value else ."/>
                        </xf:action>
                </xf:input>
             
               
                <widget:xforms-instance-inspector xmlns:widget="http://orbeon.org/oxf/xml/widget"/>
             
    </body>
</html>


TEST.XSD
--------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.test.com/TEST"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        attributeFormDefault="unqualified" elementFormDefault="qualified"
        targetNamespace="http://www.test.com/TEST">
       
        <xsd:simpleType name="TValue">
                <xsd:restriction base="xsd:decimal">
                        <xsd:totalDigits value="15"/>
                        <xsd:whiteSpace value="collapse"/>
                        <xsd:fractionDigits value="2"/>
                        <xsd:minInclusive value="0"/>
                </xsd:restriction>
        </xsd:simpleType>
               
        <xsd:complexType name="tDocument">
                <xsd:sequence>
                        <xsd:element name="Value1" type="TValue" />
                        <xsd:element name="Value2" type="xsd:decimal" />
                        <xsd:element name="Value3" />
                        <xsd:element name="Value4" />
                </xsd:sequence>
        </xsd:complexType>
       
        <xsd:element name="Document" type="tDocument"></xsd:element>
       
</xsd:schema>

test_decimal_format.zip
Reply | Threaded
Open this post in threaded view
|

Re: Default decimal format

MarcinKula
Hi,

Any suggestion ?
Maybe I misunderstood something.

I tried with a date format in the properties.xml file

...
<property as="xs:string"  name="oxf.xforms.format.date" value="if (. castable as xs:date) then format-date(xs:date(.), '[D01]-[M01]-[Y] [ZN]', 'en', (), ()) else ."/>           
...

and it works fine.
Can I do the same with a decimal format ?

Best regards.


MarcinKula wrote
Hi,

I would like to set global decimal format (###,###,###,##0.00) to all my xform pages.
I've found in the documentation "Default Formatting based on properties".

...

My xform pages have a lot of decimal fields, that's why I want to set global decimal format
without using validate action.

How can I do it ?
Reply | Threaded
Open this post in threaded view
|

Re: Default decimal format

Erik Bruchez
Administrator
The reason is that formats apply only to xforms:output, not to  
xforms:input (except for displaying the date picked by the date  
picker, where the format does apply to xforms:input).

-Erik

On Feb 3, 2008, at 6:52 AM, MarcinKula wrote:

>
> Hi,
>
> Any suggestion ?
> Maybe I misunderstood something.
>
> I tried with a date format in the properties.xml file
>
> ...
> <property as="xs:string"  name="oxf.xforms.format.date" value="if (.
> castable as xs:date) then format-date(xs:date(.), '[D01]-[M01]-[Y]  
> [ZN]',
> 'en', (), ()) else ."/>
> ...
>
> and it works fine.
> Can I do the same with a decimal format ?
>
> Best regards.
>
>
>
> MarcinKula wrote:
>>
>> Hi,
>>
>> I would like to set global decimal format (###,###,###,##0.00) to  
>> all my
>> xform pages.
>> I've found in the documentation "Default Formatting based on  
>> properties".
>>
>> ...
>>
>> My xform pages have a lot of decimal fields, that's why I want to set
>> global decimal format
>> without using validate action.
>>
>> How can I do it ?
>>
>>
> --
> View this message in context: http://www.nabble.com/Default-decimal-format-tp15149379p15254088.html
> Sent from the ObjectWeb 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
--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.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