Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    OnKeyUp(KeyupEvent event) returns null for "-"

    Hello,

    Using
    SmartClient Version: v8.3p_2013-04-19/PowerEdition Deployment (built 2013-04-19)

    I have the following code which works fine for "a-zA-Z" however it has strKeyName = null when the user types in a "-".

    Why is this? And now can I get the dash. Looking for the mask that must be defaulting somewhere.

    Thanks,
    Evan

    KeyUpHandler keyUpHandler = new KeyUpHandler() {
    @Override
    public void onKeyUp(KeyUpEvent event) {
    String strKeyName = event.getKeyName();
    handleTextItemKeyUp(strKeyName);
    }
    };
    textItem.addKeyUpHandler(keyUpHandler);

    #2
    no effect

    textItem.setKeyPressFilter("[a-zA-Z-]");

    I tried this, still get null for -

    Likely not a legal regular expression, perhaps I need \-

    Evan

    Comment


      #3
      dash

      java does not let me put in \-, nor \x2d

      perhaps this is the wrong idea.

      evan

      Comment


        #4
        hmm

        I changed to

        keypresshandler and that seems to have fixed the problem.

        looks like a bug in the other handler ...?

        Evan

        Comment


          #5
          You need to use "\\" to escape a character in a regex specified as a Java String.

          "\-", as far as a Java String is concerned, is an attempt to escape "-", which is not considered a special character in a normal Java String. "\\" causes a single slash character to be part of the String, where it is interpreter as escaping "-" in the regex, where "-" *is* a special character.

          Comment


            #6
            Hello

            Hello,

            Great good to know about the \\.

            However, why does it work when I change handlers? Why would one handler see "-" as null and the other does not??

            Seems like a bug ...

            Evan

            Comment


              #7
              Try it with a regex that actually allows the character. Otherwise, the character never appears in the field, and in that case, depending on the browser, we might not be able to reliably tell you what character was entered (this gets especially complex with IMEs).

              Comment


                #8
                nothing to do with regular expression and filters

                Hello,

                the bug I am reporting has nothing to do with filters and regular expressions.

                "-" dash has always been accepted.

                The behavior of the handlers differs, see my previous posts.

                One one case the dash is typed in and the handlers returns null in the other returns the dash. However, in both cases the dash is typed in and in both cases the browser is the same. Firefox current version.

                Evan

                Comment


                  #9
                  So again, the browser natively makes only the character code available in some handlers.

                  We generally get the maximum information in keyPress... but there are details you don't want to know, and we wish we didn't :)

                  Comment

                  Working...
                  X