0

Leading zero in Intbox

asked 2009-11-16 08:13:19 +0800

Miyuki gravatar image Miyuki flag of South Africa
45 4
http://www.e-intelligence...

Hi there guru's.

i have a very simple request.
is it possible to have a leading zero in an intbox with a contraint?
ideally I would like to apply this in the zul with minimal java code.

how does one do this?
<intbox id="postalCode" constraint="allow leading zero" width="150px"/>

(ok, allow leading zero doesnt work, i know... just asking for some help here please)

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2009-11-16 08:46:08 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

Use the format attribute on the intbox that's inherited from FormatInputElement

link publish delete flag offensive edit

answered 2009-11-16 09:46:39 +0800

mixgho gravatar image mixgho
193 3

I think this is not going to work.
I'd recommend using TypeConverter:

public class PrependZeroConverter implements TypeConverter {

	public Object coerceToBean(Object aArg0, Component aArg1) {
		return aArg0;
	}

	public Object coerceToUi(Object aArg0, Component aArg1) {
		return "0".concat(aArg0.toString());
	}
}

Of course, do some null checks :)

link publish delete flag offensive edit

answered 2009-11-16 19:55:17 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi,mixgho
because the type of variable in the setValue method of the zk intbox is int
java int isn't allow leading zero
you can type leading zero value in intbox, but leading zero value will convert to java int, and it not leading zero
maybe you can use textbox and constraint
<textbox constraint="/.[0-9]+/"/>

link publish delete flag offensive edit

answered 2009-11-17 00:09:58 +0800

Miyuki gravatar image Miyuki flag of South Africa
45 4
http://www.e-intelligence...

hi there!

caclark ->thank you for the suggestion, i failed to find a quick solution tho :(
mixgho -> i didnt want to write anything else but apply zul attributes to do this quickly. its just a small thing so i wanted a small solution
as1225 -> i initially had a textbox but later changed it to int box, only to now discover i have funky data in the db... aiyor

anyways, point is, i used as1225 recomendation and using a textbox.
thank you all for the help provided!!
I really appreciate it!!!

link publish delete flag offensive edit

answered 2011-03-31 19:25:57 +0800

kamuiken gravatar image kamuiken
3

actually... i'll change this: /.[0-9]+/ for /[0-9]+/.... it will allow ANY character at the beginning, only digits.... hope it helps!! (y)

link publish delete flag offensive edit

answered 2011-04-01 04:29:36 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

If you need a validation for it have a look here.

link publish delete flag offensive edit

answered 2011-04-03 17:38:38 +0800

Fujitsu gravatar image Fujitsu
117 2

It would be nice if ZK had a NumberBox, its pretty easy to do in pure javascript:

<HTML>
   <HEAD>
   <SCRIPT language=Javascript>
      <!--
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
      //-->
   </SCRIPT>
   </HEAD>
   <BODY>
      <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar">
   </BODY>
</HTML>

link publish delete flag offensive edit
Your reply
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

Follow

RSS

Stats

Asked: 2009-11-16 08:13:19 +0800

Seen: 1,456 times

Last updated: Apr 03 '11

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