开发者

Grails - How to format a value in a textfield into comma style such that it can be easily read?

I want to allow users enter numbers in textfield and once the textbox loses focus. The number is formatted with commas.

e.g. User enters 100000

textfield looses focus

value displayed: 100,000

How can I achieve this in Grails.

开发者_高级运维

I have looked at

<g:formatNumber number="${myNumber}" format="\\$###,##0" />

But it doesnt solve my problem as the number is from a textfield.

thanks

Much appreciated.


Well, you have to understand the difference between code that is executed on the server-side vs. client-side scripting. Your requirement "once the textbox loses focus" just can't be met by Grails, because detecting focus loss of DOM elements and reacting to it happens entierely in the user's browser. You will have to do this in JavaScript (which isn't a big deal either). For example these two jQuery plugins should do the trick (but there are plenty of other solutions, also for other JS libraries).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜