I have a numeric input field in my form. I just add some format on it with xxf:format :
<xf:input
id="input-control"
bind="input-bind"
class="question nombre"
xxf:format="if (. castable as xs:integer)
then replace(format-number(xs:integer(.),'###,###,###,###,###,###,###,###,###,##0'),',',' ')
else ''">
This may look a bit wild but it's just a format where number 123456 will be presented as 123 456. This works great for me, but not for users... So now, I added a script to cancel formatting when input is focused (aka : go back to 123456 when editing the field) with a simple js :
<xf:action ev:event="DOMFocusIn">
<xxf:script>
var input = this.getElementsByTagName('input')[0];
var valeur = input.value.replace(' ','');
input.value = valeur;
</xxf:script>
</xf:action>
Behaviour looks ok at first sight, I mean, I entered 123456, focus out and got 123 456 (format ok), focus in and got 123456 (script behaviour ok). But if I don't make any changes on the field and focus out, I don't have the format back (still 123456 instead of 123 456). I understand that the format is only applied when "needed" and "needed" means here, when the value of the input changes. But if I force an xforms-value-change event I still don't have the format back.
Anyone has an idea on how to achieve this ?
(anyone has understood anything ? :-s)
This can be tricky to get right. I would recommend using instead the fr:number
control, which does all of this for you.