Dec 6, 2011 4:32 AM
170 Posts
topic has been resolvedResolved

Setting number field to more than 999 gives not a valid number

  • Category: Dojo and Client Side JavaScript
  • Platform: Not Applicable
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 4
 I'm connecting an editbox with a number and setting in thru SSJS.
If the value is above 999 the value in the field is 1 000 in front end but in backend it's 1000 
 
I'm setting the field with 1000 and it ends up 1 000 and the validation kicks in and says that the field is not a valid number. 
 
Any suggestions how to fix this? 
 
/Fredrik 
  
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

<xp:this.data>
<xp:dominoDocument var="document1" formName="testnumber"></xp:dominoDocument>
</xp:this.data>
<xp:inputText id="inputText1" value="#{viewScope.number}">
<xp:this.converter>
<xp:convertNumber type="number"></xp:convertNumber>
</xp:this.converter>
</xp:inputText>
<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="inputText1">
<xp:this.action><![CDATA[#{javascript:viewScope.number=@TextToNumber("1000")}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button value="Label" id="button2"><xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action>
<xp:saveDocument var="document1"></xp:saveDocument>
</xp:this.action></xp:eventHandler></xp:button>
</xp:view>
 
Dec 6, 2011 4:46 AM
170 Posts
Re: Setting number field to more than 999 gives not a valid number
 Found the solution
 
if I set the scoped variable with 
 
viewScope.number="1000"  it will work but if I set it to number
viewScope.number=@TextToNumber("1000") I get the error
 
But everybody understood that but me ;-) 
 
 
/Fredrik 
 
Dec 6, 2011 4:48 AM
272 Posts
Re: Setting number field to more than 999 gives not a valid number
Hi Fredrik,
 
this is caused by the local settings. I have "punctation for thousands" enabled (1.000), and your code works.
If I replace the dot with a space, the validation error raises.
 
You can fix this by changing the converter:
 
<xp:converterNumber pattern="0" >
 
And now you won't return a simple "1000".
 
Hope this helps
Sven
 
Dec 6, 2011 8:19 AM
170 Posts
Re: Setting number field to more than 999 gives not a valid number
 It only helps if you only allow integers in the field. but if the user also can write 2999.5 
then nothing is written to the field. 
 
And the strange part is if you write 2999.5 then the number is correct but if you write 2999 then 
you get the space and the number is treated as invalid. 
 
/Fredrik 
Dec 7, 2011 7:52 AM
129 Posts
Re: Setting number field to more than 999 gives not a valid number
You could write a custom converter to handle the data.
 
I use this snippet when I'm working with numbers/converters: 
http://dontpanic82.blogspot.com/2010/04/xpages-code-for-numberstring-conversion.html