nikhilbchilwant / google-web-toolkit-incubator

Automatically exported from code.google.com/p/google-web-toolkit-incubator
1 stars 1 forks source link

CurrencyWidget/CurrencyWidgetWithPreview not editable when the input is long. #257

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What version of gwt and gwt-incubator are you using?
gwt 1.5.3, incubator r1337 (Fri, 19 Dec 2008)

What OS and browser are you using?
OS: ubuntu 8.04, WinXP sp3
BR: IE7, SeaMonkey 1.1.14, 1.1.15, FF 3.0.7

Do you see this error in hosted mode, web mode, or both?
Both. When it is frozen -> in web mode you can right-click on the currency
TextBox and delete some characters and than it works again. In hosted mode
no right-click is possible so this workaround doesn't work there.

(If possible, please include a test case that shows the problem)

Hopefully using the test case you have generously provided, what steps will
reproduce the problem? 
1.

Click the link for the most recent gwt-incubator demos in:
http://code.google.com/p/google-web-toolkit-incubator/wiki/Documentation?tm=6
(http://collectionofdemos.appspot.com/demo/index.html)

2.

When using IE7 - no demos appear (can you please build them for IE, too?)
When using SM,FF -> go to CurrencyWidgetDemo.

3.

Enter some long number in the widget (for example: 1111111111111111)
and try to edit it or delete some characters with delete/backspace.
It is not possible until you use the above workaround.

What is the expected output? What do you see instead?

It should be always editable regardless of the input length.
I see uneditable TextBox.

Workaround if you have one:
In web mode you can right-click on the currency TextBox and delete some
characters and than it works again. In hosted mode no right-click is
possible so this workaround doesn't work there.

Please provide any additional information below,  and thank you for taking
the time and effort to report this issue, as good issue reports are
critical for our quest to make GWT's new widgets and libraries shine.

There is no way of controlling the length of the decimal places after a
period in the yellow popup panel in CurrencyWidgetWithPreview widget. They
are fixed for two places.

Original issue reported on code.google.com by igor.sec...@gmail.com on 25 Mar 2009 at 11:59

GoogleCodeExporter commented 8 years ago
Yes, it is possible to display more decimal places by overriding the
getCurrencyAmountPattern for example: 

public class MyCurrencyWidgetWithPreview extends CurrencyWidgetWithPreview {
    public MyCurrencyWidgetWithPreview() {
    }
    public MyCurrencyWidgetWithPreview(String currencyCode) {
        super(currencyCode);        
    }
    protected String getCurrencyAmountPattern() {
         String CurrencyAmountPattern =  super.getCurrencyAmountPattern();
         System.out.print(CurrencyAmountPattern);        
         return CurrencyAmountPattern + "00";
     }   
}

Original comment by igor.sec...@gmail.com on 25 Mar 2009 at 2:56

GoogleCodeExporter commented 8 years ago
For me it works when I change the onKeyPress in (My)CurrencyWidget like this:

public void onKeyPress(Widget sender, char keyCode, int modifiers) {
  if (acceptableCharset.indexOf(keyCode) == -1) {
    amountBox.cancelKey();
  }
  if ( amountBox.getText().length() >= 16               
       && (keyCode != (char) KEY_TAB) && (keyCode != (char) KEY_BACKSPACE)
       && (keyCode != (char) KEY_DELETE) && (keyCode != (char) KEY_ENTER)
       && (keyCode != (char) KEY_HOME) && (keyCode != (char) KEY_END)
       && (keyCode != (char) KEY_LEFT) && (keyCode != (char) KEY_UP)
       && (keyCode != (char) KEY_RIGHT) && (keyCode != (char) KEY_DOWN)
       && amountBox.getSelectionLength() == 0
     ) {
     amountBox.cancelKey();
  }
}

(And I made the NumberFormat formatter accessible to have more decimal digits.)

Original comment by igor.sec...@gmail.com on 25 Mar 2009 at 10:14

GoogleCodeExporter commented 8 years ago

Next I needed to set the amount using a setter:

CurrencyWidgetWithPreview
-------------------------

  public void setAmount(double amount) {
      amountBox.setText(formatter.format(amount));
      String str = reformatContent();
      valueInitiated = true;      
      int pos = str.indexOf(decimalSeparator);
      previewField.setHTML("<div class='previewPanel'>"
          + "<span class='integerPart'>" + str.substring(0, pos + 1)
          + "</span>" + "<span class='decimalPart'>" + str.substring(pos + 1)
          + "</span></div>");
  }

And I wanted to enter negative numbers, too:

CurrencyWidget
--------------

 private static String getAcceptedCharset() {
    if (!GWT.isClient()) {
      return null;
    }
    StringBuffer strbuf = new StringBuffer();
    strbuf.append("-0123456789");                      // added minus sign to accept

 ....
 ....
 ....

  public void onKeyPress(Widget sender, char keyCode, int modifiers) {
      if (acceptableCharset.indexOf(keyCode) == -1) {
        amountBox.cancelKey();
      }
      if ( amountBox.getText().length() >= MaxTypeLength                
           && (keyCode != (char) KEY_TAB) && (keyCode != (char) KEY_BACKSPACE)
           && (keyCode != (char) KEY_DELETE) && (keyCode != (char) KEY_ENTER)
           && (keyCode != (char) KEY_HOME) && (keyCode != (char) KEY_END)
           && (keyCode != (char) KEY_LEFT) && (keyCode != (char) KEY_UP)
           && (keyCode != (char) KEY_RIGHT) && (keyCode != (char) KEY_DOWN)
           && amountBox.getSelectionLength() == 0
         ) 
      {
         amountBox.cancelKey();
      }
      else if (keyCode == '-' && (amountBox.getText().contains("-") ||
amountBox.getCursorPos() != 0 )) {
        amountBox.cancelKey();
      }        
  }

Original comment by igor.sec...@gmail.com on 31 Mar 2009 at 1:51