2

Doublebox decimal point . or ,

asked 2014-04-09 12:46:50 +0800

Neus gravatar image Neus
1415 14

Hi, Is there any possibility in a doublebox to interpret both , or . as a decimal point???

Thank you!

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-04-14 09:15:39 +0800

Neus gravatar image Neus
1415 14

updated 2014-04-14 10:06:22 +0800

I finally solved it using JavaScript and the code provided by link text this way:

$('.z-doublebox').each(function () {
   $(this).keypress(function(e){
       // '46' is the keyCode for '.'
       if(e.keyCode == '46' || e.charCode == '46'){
           // IE
           if(document.selection){
               // Determines the selected text. If no text selected,
               // the location of the cursor in the text is returned
               var range = document.selection.createRange();
               // Place the comma on the location of the selection,
               // and remove the data in the selection
               range.text = ',';
               // Chrome + FF
           }else if(this.selectionStart || this.selectionStart == '0'){
               // Determines the start and end of the selection.
               // If no text selected, they are the same and
               // the location of the cursor in the text is returned
               // Don't make it a jQuery obj, because selectionStart 
               // and selectionEnd isn't known.
               var start = this.selectionStart;
               var end = this.selectionEnd;
               // Place the comma on the location of the selection,
               // and remove the data in the selection
               $(this).val($(this).val().substring(0, start) + ','
                       + $(this).val().substring(end, $(this).val().length));
               // Set the cursor back at the correct location in 
               // the text
               this.selectionStart = start + 1;
               this.selectionEnd = start +1;
           }else{
               // if no selection could be determined, 
               // place the comma at the end.
               $(this).val($(this).val() + ',');             
           }
           return false;
       }
   });
 });

It replaces the '.' for a ',' when '.' key is pressed

link publish delete flag offensive edit
0

answered 2014-04-14 05:55:35 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Yes use format attribute of DoubleBox Component

<doublebox format="#,##0.##"/>
link publish delete flag offensive edit

Comments

With which locale? As I know, the component takes the default locale, in my case es, it means , is decimal separator and . thousand separator

Neus ( 2014-04-14 07:54:19 +0800 )edit

What do you mean by locale? You already set locale in your application level

sjoshi ( 2014-04-14 08:11:16 +0800 )edit

Yes, and the locale is ES so it means that , is decimal separator and . thousand separator. What I need is that no matter if , key or . key is pressed it acts as the decimal separator. Like in Windows calculator where no matter if I press . key or , key it is replaced to the decimal separator

Neus ( 2014-04-14 08:35:23 +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

Follow
1 follower

RSS

Stats

Asked: 2014-04-09 12:46:50 +0800

Seen: 37 times

Last updated: Apr 14 '14

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