Global DecimalBox onChanging currency format

asked 2018-04-10 06:30:10 +0800

psinalberth gravatar image psinalberth
52 6


I'd like to format a DecimalBox as I type the numbers. I know there is the onChanging event where I could do that, but I'm a little bit lost thinking of how could I write something like that.

A friend of mine wrote a piece of code which applies some mask to a textbox by using the onKeyUp event, but it is a local feature and it would be necessary include it every time I'd need to apply this mask. That's the fiddle: http://zkfiddle.org/sample/144bqmi/1-Another-new-ZK-fiddle

Is there a way to write a code like that and invoke it like <textbox onChanging="myscript">?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-04-10 15:50:43 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

updated 2018-04-10 15:54:12 +0800

onChanging is a server side event listener, and your scenario sounds like it's better dealt with at client side to provide a better user experience. So here a few thoughts on improving the maintainability of your js code, avoiding duplication:

Inside a client side listener it is possible to call functions from separate js files which makes the function reusable in a very basic way. http://zkfiddle.org/sample/144bqmi/2-separate-mask-function

If you don't like functions polluting the global namespace you can add a custom maskInput function directly to the zul.inp.Textbox.prototype as in this example http://zkfiddle.org/sample/144bqmi/3-add-mask-function-to-textbox-widget

If you want to go deeper into client side customization e.g. extending an existing widget class with your own implementation I'd refer to the client side reference: https://www.zkoss.org/wiki/ZKClient-sideReference/GeneralControl/WidgetCustomization

For your case I think either my first or second option should provide a manageable mechanism.

Please let me know if this information was sufficient or not.


link publish delete flag offensive edit


Yes, I was looking for something like this. Could I put a script on zk.xml and then invoke a function? I'm pretty sure I've read something about but I don't remember where it was.

psinalberth ( 2018-04-10 18:01:19 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2018-04-10 06:30:10 +0800

Seen: 14 times

Last updated: Apr 10 '18

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More