You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Bruce Atherton <br...@callenish.com> on 2005/11/08 02:04:56 UTC

Integer formatting

I have what I consider very odd behaviour in my forms. Specifically, 
javascript variables are being rendered as floats rather than integers 
in the HTML, but only if I tell the forms to render them as plain integers.

So if I have the following flowscript:

    formData.queueList = [
      {value: 1, label:"1"},
      {value: 2, label:"2"},
      {value: 3, label:"3"}
    ];

with a form definition that looks something like this:

    <fd:field id="queue" >
        <fd:label><i18n:text>Select Queue #</i18n:text></fd:label>
        <fd:datatype base="integer" />
        <fd:selection-list type="flow-jxpath" list-path="queueList" 
value-path="value" label-path="label" />
    </fd:field>

things work great. But if I change the definition file to:

    <fd:field id="queue" >
        <fd:label><i18n:text>Select Queue #</i18n:text></fd:label>
        <fd:datatype base="integer" >
            <fd:convertor type="plain" variant="integer" />
        </fd:datatype>
        <fd:selection-list type="flow-jxpath" list-path="queueList" 
value-path="value" label-path="label" />
    </fd:field>

what comes out in the HTML is:

    <select class="repeater-form-widget" id="queueList.0.instance" name="queueList.0.instance">
        <option value="1.0" selected="true">1</option>
        <option value="2.0" selected="true">2</option>
        etc...

Note the floating point value. When submitting the form, the dropdown 
ends up with an exclamation point beside it because it doesn't pass 
validation, 1.0 not being an integer value.

I can fix the problem by using Java types rather than the javascript 
variables in the flow. So this renders as integers in the HTML rather 
than floats:

    formData.queueList = [
      {value: new Integer(1), label:"1"},
      {value: new Integer(2), label:"2"},
      {value: new Integer(3), label:"3"}
    ];

but it strikes me as a weird behaviour.

Is this expected, or is it a bug? What is the recommended implementation 
for this?

P.S.  I know that I don't need a convertor in this particular case, but 
I am trying to be consistent in how integers are handled and I don't 
want commas in integers under any circumstances. There are lots of other 
places where my integers can go over four digits.


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