You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by William Speirs <ws...@apache.org> on 2013/03/10 20:38:53 UTC

NumberTextField Issue

I'm trying to use a NumberTextField with a type of Double and the form will
only let me type in integers (or doubles that end in .0). Is this a known
issue? Is there a workaround?

My basic code...

*Java*
    private IModel<Double> doubleModel;

        final NumberTextField<Double> d = new NumberTextField<Double>("d",
doubleModel, Double.class);

        d.setMinimum(1.0d);
        d.setMaximum(1000.0d);
        d.setRequired(true);

        form.add(d);

*HTML*

                  <div class="control-group">
                    <label class="control-label" for="d">Double</label>
                    <div class="controls">
                      <input type="number" wicket:id="d"></input>
                    </div>
                  </div>


Am I using the wrong component or HTML input type or something? Every time
I type in a number like 5.5 and try to submit the form I get the pop-up
that say, "Invalid value."

Thoughts?

Thanks...

Bill-

Re: NumberTextField Issue

Posted by Paul Bors <pa...@bors.ws>.
Funny, I never had to use the number attribute thus far. But I'm using HTMl 4.01 and not 5.

In HTML my browser can input decimals so it could be something else funky.

~ Thank you,
   Paul C Bors

On Mar 10, 2013, at 16:26, William Speirs <ws...@apache.org> wrote:

> I tried that and get the following:
> 
> Component must be applied to a tag with [type] attribute matching [number],
> not [text]
> 
> So it really wants it to be a number... just not sure why it won't accept
> decimals.
> 
> Thanks...
> 
> Bill-
> 
> 
> On Sun, Mar 10, 2013 at 4:11 PM, Paul Bors <pa...@bors.ws> wrote:
> 
>> Your HTML input type is "number", try using "text" as Wicket would use its
>> internal converter to convert (cast) the string user input in HTML to the
>> backing model object type (double in your case).
>> 
>> HTML input tag:
>> http://www.w3schools.com/tags/att_input_type.asp
>> 
>> Wicket custom converters:
>> https://cwiki.apache.org/WICKET/using-custom-converters.html
>> Wicket's double converter:
>> 
>> http://wicket.apache.org/apidocs/1.5/org/apache/wicket/util/convert/converter/DoubleConverter.html
>> 
>> As a side note, I've noticed you're using the label's for attribute which
>> wicket supports in different formats.
>> 
>> Take a look at the Wicket's XHTML tags:
>> 
>> https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html#Wicket%2527sXHTMLtags-Attributewicket%253Afor
>> And also in Java as FormComponentLabel:
>> 
>> http://wicket.apache.org/apidocs/1.5/org/apache/wicket/markup/html/form/FormComponentLabel.html
>> 
>> ~ Thank you,
>>   Paul C Bors
>> 
>> On Mar 10, 2013, at 15:38, William Speirs <ws...@apache.org> wrote:
>> 
>>> I'm trying to use a NumberTextField with a type of Double and the form
>> will
>>> only let me type in integers (or doubles that end in .0). Is this a known
>>> issue? Is there a workaround?
>>> 
>>> My basic code...
>>> 
>>> *Java*
>>>   private IModel<Double> doubleModel;
>>> 
>>>       final NumberTextField<Double> d = new NumberTextField<Double>("d",
>>> doubleModel, Double.class);
>>> 
>>>       d.setMinimum(1.0d);
>>>       d.setMaximum(1000.0d);
>>>       d.setRequired(true);
>>> 
>>>       form.add(d);
>>> 
>>> *HTML*
>>> 
>>>                 <div class="control-group">
>>>                   <label class="control-label" for="d">Double</label>
>>>                   <div class="controls">
>>>                     <input type="number" wicket:id="d"></input>
>>>                   </div>
>>>                 </div>
>>> 
>>> 
>>> Am I using the wrong component or HTML input type or something? Every
>> time
>>> I type in a number like 5.5 and try to submit the form I get the pop-up
>>> that say, "Invalid value."
>>> 
>>> Thoughts?
>>> 
>>> Thanks...
>>> 
>>> Bill-
>> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: NumberTextField Issue

Posted by William Speirs <ws...@apache.org>.
I tried that and get the following:

Component must be applied to a tag with [type] attribute matching [number],
not [text]

So it really wants it to be a number... just not sure why it won't accept
decimals.

Thanks...

Bill-


On Sun, Mar 10, 2013 at 4:11 PM, Paul Bors <pa...@bors.ws> wrote:

> Your HTML input type is "number", try using "text" as Wicket would use its
> internal converter to convert (cast) the string user input in HTML to the
> backing model object type (double in your case).
>
> HTML input tag:
> http://www.w3schools.com/tags/att_input_type.asp
>
> Wicket custom converters:
> https://cwiki.apache.org/WICKET/using-custom-converters.html
> Wicket's double converter:
>
> http://wicket.apache.org/apidocs/1.5/org/apache/wicket/util/convert/converter/DoubleConverter.html
>
> As a side note, I've noticed you're using the label's for attribute which
> wicket supports in different formats.
>
> Take a look at the Wicket's XHTML tags:
>
> https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html#Wicket%2527sXHTMLtags-Attributewicket%253Afor
> And also in Java as FormComponentLabel:
>
> http://wicket.apache.org/apidocs/1.5/org/apache/wicket/markup/html/form/FormComponentLabel.html
>
> ~ Thank you,
>    Paul C Bors
>
> On Mar 10, 2013, at 15:38, William Speirs <ws...@apache.org> wrote:
>
> > I'm trying to use a NumberTextField with a type of Double and the form
> will
> > only let me type in integers (or doubles that end in .0). Is this a known
> > issue? Is there a workaround?
> >
> > My basic code...
> >
> > *Java*
> >    private IModel<Double> doubleModel;
> >
> >        final NumberTextField<Double> d = new NumberTextField<Double>("d",
> > doubleModel, Double.class);
> >
> >        d.setMinimum(1.0d);
> >        d.setMaximum(1000.0d);
> >        d.setRequired(true);
> >
> >        form.add(d);
> >
> > *HTML*
> >
> >                  <div class="control-group">
> >                    <label class="control-label" for="d">Double</label>
> >                    <div class="controls">
> >                      <input type="number" wicket:id="d"></input>
> >                    </div>
> >                  </div>
> >
> >
> > Am I using the wrong component or HTML input type or something? Every
> time
> > I type in a number like 5.5 and try to submit the form I get the pop-up
> > that say, "Invalid value."
> >
> > Thoughts?
> >
> > Thanks...
> >
> > Bill-
>

Re: NumberTextField Issue

Posted by Paul Bors <pa...@bors.ws>.
Your HTML input type is "number", try using "text" as Wicket would use its internal converter to convert (cast) the string user input in HTML to the backing model object type (double in your case).

HTML input tag:
http://www.w3schools.com/tags/att_input_type.asp

Wicket custom converters:
https://cwiki.apache.org/WICKET/using-custom-converters.html
Wicket's double converter:
http://wicket.apache.org/apidocs/1.5/org/apache/wicket/util/convert/converter/DoubleConverter.html

As a side note, I've noticed you're using the label's for attribute which wicket supports in different formats.

Take a look at the Wicket's XHTML tags:
https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html#Wicket%2527sXHTMLtags-Attributewicket%253Afor
And also in Java as FormComponentLabel:
http://wicket.apache.org/apidocs/1.5/org/apache/wicket/markup/html/form/FormComponentLabel.html

~ Thank you,
   Paul C Bors

On Mar 10, 2013, at 15:38, William Speirs <ws...@apache.org> wrote:

> I'm trying to use a NumberTextField with a type of Double and the form will
> only let me type in integers (or doubles that end in .0). Is this a known
> issue? Is there a workaround?
> 
> My basic code...
> 
> *Java*
>    private IModel<Double> doubleModel;
> 
>        final NumberTextField<Double> d = new NumberTextField<Double>("d",
> doubleModel, Double.class);
> 
>        d.setMinimum(1.0d);
>        d.setMaximum(1000.0d);
>        d.setRequired(true);
> 
>        form.add(d);
> 
> *HTML*
> 
>                  <div class="control-group">
>                    <label class="control-label" for="d">Double</label>
>                    <div class="controls">
>                      <input type="number" wicket:id="d"></input>
>                    </div>
>                  </div>
> 
> 
> Am I using the wrong component or HTML input type or something? Every time
> I type in a number like 5.5 and try to submit the form I get the pop-up
> that say, "Invalid value."
> 
> Thoughts?
> 
> Thanks...
> 
> Bill-

Re: NumberTextField Issue

Posted by Bill Speirs <bi...@gmail.com>.
Done: https://issues.apache.org/jira/browse/WICKET-5096

Thanks...

Bill-

On Tue, Mar 12, 2013 at 5:12 PM, Martin Grigorov <mg...@apache.org> wrote:
> Please file a ticket to add the step attribute.
> Thanks!
>
>
> On Tue, Mar 12, 2013 at 12:48 AM, William Speirs <ws...@apache.org> wrote:
>
>> OK... so it's not Wicket related, it is a combination of Bootstrap + Chrome
>> + HTML5. This blog post I found actually explains it quite well:
>>
>> http://blog.isotoma.com/2012/03/html5-input-typenumber-and-decimalsfloats-in-chrome/
>>
>> The short version is that there is a step attribute when an input's type is
>> number. If you don't specify a step then it defaults to 1 making decimal
>> values invalid. As soon as I set step="0.01" it worked like a champ (I did
>> that because it's a currency, but you can also set step="any").
>>
>> Coming back to Wicket, since the NumberTextField component has the ability
>> to setMaximum & setMinimum, should it also have a setStep method? Otherwise
>> you're forced to use a combination of Wicket methods & HTML attributes to
>> control the input box.
>>
>> Thoughts?
>>
>> Bill-
>>
>>
>> On Mon, Mar 11, 2013 at 4:51 PM, William Speirs <ws...@apache.org>
>> wrote:
>>
>> > I'll need to double check and get back to you, but I think it might be a
>> > bootstrap issue. The input box gets styled with controls to increase and
>> > decrease the number and that might be the issue.
>> >
>> > Thanks...
>> >
>> > Bill-
>> > On Mar 11, 2013 5:30 AM, "Martin Grigorov" <mg...@apache.org> wrote:
>> >
>> >> Hi,
>> >>
>> >>
>> >> On Sun, Mar 10, 2013 at 9:38 PM, William Speirs <ws...@apache.org>
>> >> wrote:
>> >>
>> >> > I'm trying to use a NumberTextField with a type of Double and the form
>> >> will
>> >> > only let me type in integers (or doubles that end in .0). Is this a
>> >> known
>> >> > issue? Is there a workaround?
>> >> >
>> >>
>> >> Can you explain more ? I don't remember having such restrictions when I
>> >> used NTF.
>> >> Which browser do you use ?
>> >> Can you create a plain HTML file (without using Wicket) and try to use
>> >> <input type="number" .../> with a double with higher precision ?
>> >>
>> >>
>> >> >
>> >> > My basic code...
>> >> >
>> >> > *Java*
>> >> >     private IModel<Double> doubleModel;
>> >> >
>> >> >         final NumberTextField<Double> d = new
>> >> NumberTextField<Double>("d",
>> >> > doubleModel, Double.class);
>> >> >
>> >> >         d.setMinimum(1.0d);
>> >> >         d.setMaximum(1000.0d);
>> >> >         d.setRequired(true);
>> >> >
>> >> >         form.add(d);
>> >> >
>> >> > *HTML*
>> >> >
>> >> >                   <div class="control-group">
>> >> >                     <label class="control-label"
>> for="d">Double</label>
>> >> >                     <div class="controls">
>> >> >                       <input type="number" wicket:id="d"></input>
>> >> >                     </div>
>> >> >                   </div>
>> >> >
>> >> >
>> >> > Am I using the wrong component or HTML input type or something? Every
>> >> time
>> >> > I type in a number like 5.5 and try to submit the form I get the
>> pop-up
>> >> > that say, "Invalid value."
>> >> >
>> >> > Thoughts?
>> >> >
>> >> > Thanks...
>> >> >
>> >> > Bill-
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Martin Grigorov
>> >> jWeekend
>> >> Training, Consulting, Development
>> >> http://jWeekend.com <http://jweekend.com/>
>> >>
>> >
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com <http://jweekend.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: NumberTextField Issue

Posted by Martin Grigorov <mg...@apache.org>.
Please file a ticket to add the step attribute.
Thanks!


On Tue, Mar 12, 2013 at 12:48 AM, William Speirs <ws...@apache.org> wrote:

> OK... so it's not Wicket related, it is a combination of Bootstrap + Chrome
> + HTML5. This blog post I found actually explains it quite well:
>
> http://blog.isotoma.com/2012/03/html5-input-typenumber-and-decimalsfloats-in-chrome/
>
> The short version is that there is a step attribute when an input's type is
> number. If you don't specify a step then it defaults to 1 making decimal
> values invalid. As soon as I set step="0.01" it worked like a champ (I did
> that because it's a currency, but you can also set step="any").
>
> Coming back to Wicket, since the NumberTextField component has the ability
> to setMaximum & setMinimum, should it also have a setStep method? Otherwise
> you're forced to use a combination of Wicket methods & HTML attributes to
> control the input box.
>
> Thoughts?
>
> Bill-
>
>
> On Mon, Mar 11, 2013 at 4:51 PM, William Speirs <ws...@apache.org>
> wrote:
>
> > I'll need to double check and get back to you, but I think it might be a
> > bootstrap issue. The input box gets styled with controls to increase and
> > decrease the number and that might be the issue.
> >
> > Thanks...
> >
> > Bill-
> > On Mar 11, 2013 5:30 AM, "Martin Grigorov" <mg...@apache.org> wrote:
> >
> >> Hi,
> >>
> >>
> >> On Sun, Mar 10, 2013 at 9:38 PM, William Speirs <ws...@apache.org>
> >> wrote:
> >>
> >> > I'm trying to use a NumberTextField with a type of Double and the form
> >> will
> >> > only let me type in integers (or doubles that end in .0). Is this a
> >> known
> >> > issue? Is there a workaround?
> >> >
> >>
> >> Can you explain more ? I don't remember having such restrictions when I
> >> used NTF.
> >> Which browser do you use ?
> >> Can you create a plain HTML file (without using Wicket) and try to use
> >> <input type="number" .../> with a double with higher precision ?
> >>
> >>
> >> >
> >> > My basic code...
> >> >
> >> > *Java*
> >> >     private IModel<Double> doubleModel;
> >> >
> >> >         final NumberTextField<Double> d = new
> >> NumberTextField<Double>("d",
> >> > doubleModel, Double.class);
> >> >
> >> >         d.setMinimum(1.0d);
> >> >         d.setMaximum(1000.0d);
> >> >         d.setRequired(true);
> >> >
> >> >         form.add(d);
> >> >
> >> > *HTML*
> >> >
> >> >                   <div class="control-group">
> >> >                     <label class="control-label"
> for="d">Double</label>
> >> >                     <div class="controls">
> >> >                       <input type="number" wicket:id="d"></input>
> >> >                     </div>
> >> >                   </div>
> >> >
> >> >
> >> > Am I using the wrong component or HTML input type or something? Every
> >> time
> >> > I type in a number like 5.5 and try to submit the form I get the
> pop-up
> >> > that say, "Invalid value."
> >> >
> >> > Thoughts?
> >> >
> >> > Thanks...
> >> >
> >> > Bill-
> >> >
> >>
> >>
> >>
> >> --
> >> Martin Grigorov
> >> jWeekend
> >> Training, Consulting, Development
> >> http://jWeekend.com <http://jweekend.com/>
> >>
> >
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: NumberTextField Issue

Posted by William Speirs <ws...@apache.org>.
OK... so it's not Wicket related, it is a combination of Bootstrap + Chrome
+ HTML5. This blog post I found actually explains it quite well:
http://blog.isotoma.com/2012/03/html5-input-typenumber-and-decimalsfloats-in-chrome/

The short version is that there is a step attribute when an input's type is
number. If you don't specify a step then it defaults to 1 making decimal
values invalid. As soon as I set step="0.01" it worked like a champ (I did
that because it's a currency, but you can also set step="any").

Coming back to Wicket, since the NumberTextField component has the ability
to setMaximum & setMinimum, should it also have a setStep method? Otherwise
you're forced to use a combination of Wicket methods & HTML attributes to
control the input box.

Thoughts?

Bill-


On Mon, Mar 11, 2013 at 4:51 PM, William Speirs <ws...@apache.org> wrote:

> I'll need to double check and get back to you, but I think it might be a
> bootstrap issue. The input box gets styled with controls to increase and
> decrease the number and that might be the issue.
>
> Thanks...
>
> Bill-
> On Mar 11, 2013 5:30 AM, "Martin Grigorov" <mg...@apache.org> wrote:
>
>> Hi,
>>
>>
>> On Sun, Mar 10, 2013 at 9:38 PM, William Speirs <ws...@apache.org>
>> wrote:
>>
>> > I'm trying to use a NumberTextField with a type of Double and the form
>> will
>> > only let me type in integers (or doubles that end in .0). Is this a
>> known
>> > issue? Is there a workaround?
>> >
>>
>> Can you explain more ? I don't remember having such restrictions when I
>> used NTF.
>> Which browser do you use ?
>> Can you create a plain HTML file (without using Wicket) and try to use
>> <input type="number" .../> with a double with higher precision ?
>>
>>
>> >
>> > My basic code...
>> >
>> > *Java*
>> >     private IModel<Double> doubleModel;
>> >
>> >         final NumberTextField<Double> d = new
>> NumberTextField<Double>("d",
>> > doubleModel, Double.class);
>> >
>> >         d.setMinimum(1.0d);
>> >         d.setMaximum(1000.0d);
>> >         d.setRequired(true);
>> >
>> >         form.add(d);
>> >
>> > *HTML*
>> >
>> >                   <div class="control-group">
>> >                     <label class="control-label" for="d">Double</label>
>> >                     <div class="controls">
>> >                       <input type="number" wicket:id="d"></input>
>> >                     </div>
>> >                   </div>
>> >
>> >
>> > Am I using the wrong component or HTML input type or something? Every
>> time
>> > I type in a number like 5.5 and try to submit the form I get the pop-up
>> > that say, "Invalid value."
>> >
>> > Thoughts?
>> >
>> > Thanks...
>> >
>> > Bill-
>> >
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com <http://jweekend.com/>
>>
>

Re: NumberTextField Issue

Posted by William Speirs <ws...@apache.org>.
I'll need to double check and get back to you, but I think it might be a
bootstrap issue. The input box gets styled with controls to increase and
decrease the number and that might be the issue.

Thanks...

Bill-
On Mar 11, 2013 5:30 AM, "Martin Grigorov" <mg...@apache.org> wrote:

> Hi,
>
>
> On Sun, Mar 10, 2013 at 9:38 PM, William Speirs <ws...@apache.org>
> wrote:
>
> > I'm trying to use a NumberTextField with a type of Double and the form
> will
> > only let me type in integers (or doubles that end in .0). Is this a known
> > issue? Is there a workaround?
> >
>
> Can you explain more ? I don't remember having such restrictions when I
> used NTF.
> Which browser do you use ?
> Can you create a plain HTML file (without using Wicket) and try to use
> <input type="number" .../> with a double with higher precision ?
>
>
> >
> > My basic code...
> >
> > *Java*
> >     private IModel<Double> doubleModel;
> >
> >         final NumberTextField<Double> d = new
> NumberTextField<Double>("d",
> > doubleModel, Double.class);
> >
> >         d.setMinimum(1.0d);
> >         d.setMaximum(1000.0d);
> >         d.setRequired(true);
> >
> >         form.add(d);
> >
> > *HTML*
> >
> >                   <div class="control-group">
> >                     <label class="control-label" for="d">Double</label>
> >                     <div class="controls">
> >                       <input type="number" wicket:id="d"></input>
> >                     </div>
> >                   </div>
> >
> >
> > Am I using the wrong component or HTML input type or something? Every
> time
> > I type in a number like 5.5 and try to submit the form I get the pop-up
> > that say, "Invalid value."
> >
> > Thoughts?
> >
> > Thanks...
> >
> > Bill-
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com <http://jweekend.com/>
>

Re: NumberTextField Issue

Posted by Martin Grigorov <mg...@apache.org>.
Hi,


On Sun, Mar 10, 2013 at 9:38 PM, William Speirs <ws...@apache.org> wrote:

> I'm trying to use a NumberTextField with a type of Double and the form will
> only let me type in integers (or doubles that end in .0). Is this a known
> issue? Is there a workaround?
>

Can you explain more ? I don't remember having such restrictions when I
used NTF.
Which browser do you use ?
Can you create a plain HTML file (without using Wicket) and try to use
<input type="number" .../> with a double with higher precision ?


>
> My basic code...
>
> *Java*
>     private IModel<Double> doubleModel;
>
>         final NumberTextField<Double> d = new NumberTextField<Double>("d",
> doubleModel, Double.class);
>
>         d.setMinimum(1.0d);
>         d.setMaximum(1000.0d);
>         d.setRequired(true);
>
>         form.add(d);
>
> *HTML*
>
>                   <div class="control-group">
>                     <label class="control-label" for="d">Double</label>
>                     <div class="controls">
>                       <input type="number" wicket:id="d"></input>
>                     </div>
>                   </div>
>
>
> Am I using the wrong component or HTML input type or something? Every time
> I type in a number like 5.5 and try to submit the form I get the pop-up
> that say, "Invalid value."
>
> Thoughts?
>
> Thanks...
>
> Bill-
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>