You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Kamil Paśko <ka...@solsoft.pl> on 2017/10/24 11:52:47 UTC
How to format number in (Number)TextField?
Dear Wicket user group,
I have a TextField (but I can use NumberTextField as well) and when user
types a number I want that:
1) number is positioned to the right
2) thousands are separated by spaces
3) floating point character is "."
How can I "force" that format in a TextField?
Kind regards,
Kamil
Re: How to format number in (Number)TextField?
Posted by Kamil Paśko <ka...@solsoft.pl>.
Thanks!
Combining it with custom Behavior should do the trick
W dniu 2017-10-24 o 16:52, Maxim Solodovnik pisze:
> I believe by overriding textFormat you can customize the way number is
> being displayed
> And the way text is being converted to number inside wicket.
>
> to format field data while user prints you need to use JS llibrary
> for ex. this one http://flaviosilveira.com/Jquery-Price-Format/ looks
> promising ....
>
> On Tue, Oct 24, 2017 at 8:00 PM, Kamil Paśko <ka...@solsoft.pl> wrote:
>
>> Maxim,
>>
>> I tried with:
>>
>> private final class MyFormattedField extends TextField<String>
>> implements ITextFormatProvider {
>> private MyFormattedField(String id, IModel<String> model) {
>> super(id, model);
>> }
>>
>> @Override
>> public String getTextFormat() {
>> return "### ###.###";
>> }
>> }
>>
>> but this doesn't do anything.
>>
>> user can type "12321321321" and value is not formatted
>>
>>
>> W dniu 2017-10-24 o 14:37, Maxim Solodovnik pisze:
>>
>>> I believe you can override "getTextFormat <https://ci.apache.org/project
>>> s/wicket/apidocs/8.x/org/apache/wicket/markup/html/form
>>> /AbstractTextComponent.ITextFormatProvider.html#getTextFormat-->()"
>>> method and provide your own format
>>> According to right align: you can use CSS class for that :)
>>>
>>> On Tue, Oct 24, 2017 at 6:52 PM, Kamil Paśko <kamil.pasko@solsoft.pl
>>> <ma...@solsoft.pl>> wrote:
>>>
>>> Dear Wicket user group,
>>>
>>>
>>> I have a TextField (but I can use NumberTextField as well) and
>>> when user types a number I want that:
>>>
>>> 1) number is positioned to the right
>>>
>>> 2) thousands are separated by spaces
>>>
>>> 3) floating point character is "."
>>>
>>> How can I "force" that format in a TextField?
>>>
>>> Kind regards,
>>>
>>> Kamil
>>>
>>>
>>>
>>>
>>> --
>>> WBR
>>> Maxim aka solomax
>>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to format number in (Number)TextField?
Posted by Maxim Solodovnik <so...@gmail.com>.
I believe by overriding textFormat you can customize the way number is
being displayed
And the way text is being converted to number inside wicket.
to format field data while user prints you need to use JS llibrary
for ex. this one http://flaviosilveira.com/Jquery-Price-Format/ looks
promising ....
On Tue, Oct 24, 2017 at 8:00 PM, Kamil Paśko <ka...@solsoft.pl> wrote:
> Maxim,
>
> I tried with:
>
> private final class MyFormattedField extends TextField<String>
> implements ITextFormatProvider {
> private MyFormattedField(String id, IModel<String> model) {
> super(id, model);
> }
>
> @Override
> public String getTextFormat() {
> return "### ###.###";
> }
> }
>
> but this doesn't do anything.
>
> user can type "12321321321" and value is not formatted
>
>
> W dniu 2017-10-24 o 14:37, Maxim Solodovnik pisze:
>
>> I believe you can override "getTextFormat <https://ci.apache.org/project
>> s/wicket/apidocs/8.x/org/apache/wicket/markup/html/form
>> /AbstractTextComponent.ITextFormatProvider.html#getTextFormat-->()"
>> method and provide your own format
>> According to right align: you can use CSS class for that :)
>>
>> On Tue, Oct 24, 2017 at 6:52 PM, Kamil Paśko <kamil.pasko@solsoft.pl
>> <ma...@solsoft.pl>> wrote:
>>
>> Dear Wicket user group,
>>
>>
>> I have a TextField (but I can use NumberTextField as well) and
>> when user types a number I want that:
>>
>> 1) number is positioned to the right
>>
>> 2) thousands are separated by spaces
>>
>> 3) floating point character is "."
>>
>> How can I "force" that format in a TextField?
>>
>> Kind regards,
>>
>> Kamil
>>
>>
>>
>>
>> --
>> WBR
>> Maxim aka solomax
>>
>
>
--
WBR
Maxim aka solomax
Re: How to format number in (Number)TextField?
Posted by Kamil Paśko <ka...@solsoft.pl>.
Maxim,
I tried with:
private final class MyFormattedField extends TextField<String>
implements ITextFormatProvider {
private MyFormattedField(String id, IModel<String> model) {
super(id, model);
}
@Override
public String getTextFormat() {
return "### ###.###";
}
}
but this doesn't do anything.
user can type "12321321321" and value is not formatted
W dniu 2017-10-24 o 14:37, Maxim Solodovnik pisze:
> I believe you can override "getTextFormat
> <https://ci.apache.org/projects/wicket/apidocs/8.x/org/apache/wicket/markup/html/form/AbstractTextComponent.ITextFormatProvider.html#getTextFormat-->()"
> method and provide your own format
> According to right align: you can use CSS class for that :)
>
> On Tue, Oct 24, 2017 at 6:52 PM, Kamil Paśko <kamil.pasko@solsoft.pl
> <ma...@solsoft.pl>> wrote:
>
> Dear Wicket user group,
>
>
> I have a TextField (but I can use NumberTextField as well) and
> when user types a number I want that:
>
> 1) number is positioned to the right
>
> 2) thousands are separated by spaces
>
> 3) floating point character is "."
>
> How can I "force" that format in a TextField?
>
> Kind regards,
>
> Kamil
>
>
>
>
> --
> WBR
> Maxim aka solomax
Re: How to format number in (Number)TextField?
Posted by Kamil Paśko <ka...@solsoft.pl>.
I tried with:
@Override
protected void onInitialize() {
super.onInitialize();
InputMaskBehavior mask = new InputMaskBehavior() {
@Override
protected String getMask() {
return "999 999.99";
}
};
add(mask);
}
but this forces the user to type exactly what mask shows, so user can
not type:
123 nor 123.11, it must be 123 123.11
W dniu 2017-10-24 o 14:48, Francois Meillet pisze:
> You can use an input with a mask
> something like <input type="text" class="masked" data-format="999 999 999.99" >
> Have a look at https://igorescobar.github.io/jQuery-Mask-Plugin/ <https://igorescobar.github.io/jQuery-Mask-Plugin/>
>
> François
>
>
>
>> Le 24 oct. 2017 à 14:37, Maxim Solodovnik <so...@gmail.com> a écrit :
>>
>> I believe you can override "getTextFormat <https://ci.apache.org/projects/wicket/apidocs/8.x/org/apache/wicket/markup/html/form/AbstractTextComponent.ITextFormatProvider.html#getTextFormat-->()" method and provide your own format
>> According to right align: you can use CSS class for that :)
>>
>> On Tue, Oct 24, 2017 at 6:52 PM, Kamil Paśko <kamil.pasko@solsoft.pl <ma...@solsoft.pl>> wrote:
>> Dear Wicket user group,
>>
>>
>> I have a TextField (but I can use NumberTextField as well) and when user types a number I want that:
>>
>> 1) number is positioned to the right
>>
>> 2) thousands are separated by spaces
>>
>> 3) floating point character is "."
>>
>>
>>
>> How can I "force" that format in a TextField?
>>
>> Kind regards,
>>
>> Kamil
>>
>>
>>
>> --
>> WBR
>> Maxim aka solomax
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to format number in (Number)TextField?
Posted by Francois Meillet <fr...@gmail.com>.
You can use an input with a mask
something like <input type="text" class="masked" data-format="999 999 999.99" >
Have a look at https://igorescobar.github.io/jQuery-Mask-Plugin/ <https://igorescobar.github.io/jQuery-Mask-Plugin/>
François
> Le 24 oct. 2017 à 14:37, Maxim Solodovnik <so...@gmail.com> a écrit :
>
> I believe you can override "getTextFormat <https://ci.apache.org/projects/wicket/apidocs/8.x/org/apache/wicket/markup/html/form/AbstractTextComponent.ITextFormatProvider.html#getTextFormat-->()" method and provide your own format
> According to right align: you can use CSS class for that :)
>
> On Tue, Oct 24, 2017 at 6:52 PM, Kamil Paśko <kamil.pasko@solsoft.pl <ma...@solsoft.pl>> wrote:
> Dear Wicket user group,
>
>
> I have a TextField (but I can use NumberTextField as well) and when user types a number I want that:
>
> 1) number is positioned to the right
>
> 2) thousands are separated by spaces
>
> 3) floating point character is "."
>
>
>
> How can I "force" that format in a TextField?
>
> Kind regards,
>
> Kamil
>
>
>
> --
> WBR
> Maxim aka solomax
Re: How to format number in (Number)TextField?
Posted by Maxim Solodovnik <so...@gmail.com>.
I believe you can override "getTextFormat
<https://ci.apache.org/projects/wicket/apidocs/8.x/org/apache/wicket/markup/html/form/AbstractTextComponent.ITextFormatProvider.html#getTextFormat-->
()" method and provide your own format
According to right align: you can use CSS class for that :)
On Tue, Oct 24, 2017 at 6:52 PM, Kamil Paśko <ka...@solsoft.pl> wrote:
> Dear Wicket user group,
>
>
> I have a TextField (but I can use NumberTextField as well) and when user
> types a number I want that:
>
> 1) number is positioned to the right
>
> 2) thousands are separated by spaces
>
> 3) floating point character is "."
>
> How can I "force" that format in a TextField?
>
> Kind regards,
>
> Kamil
>
--
WBR
Maxim aka solomax