Hybrid View

  1. #1
    Sencha User ITS_luka's Avatar
    Join Date
    Aug 2011
    Location
    Tbilisi, Georgia
    Posts
    19
    Vote Rating
    0
    ITS_luka is on a distinguished road

      0  

    Default Answered: About TextField

    Answered: About TextField


    Hello,

    onKeyPress, textfield must change character

    e.g. when i press 'a' on my keyboard, i want my textfield type 'პ'-symbol instead.

    I know unicodeCharCodes of my sybmols. (from \u4304 to \u4336)

    how to do that?

    thank you

  2. Ah. It wasn't clear where you were at in your development. This works nicely, if however unreasonably specific. The key is event.preventDefault() since you don't want the original character rendering, without this line, both characters will render:

    Code:
    public class TextFieldKeyPressTest implements EntryPoint
    {
       @Override
       public void onModuleLoad()
       {
          ContentPanel cp = new ContentPanel();
          cp.setPixelSize(400, 400);
    
          final TextField tf = new TextField();
          tf.addKeyPressHandler(new KeyPressHandler()
          {
             @Override
             public void onKeyPress(KeyPressEvent event)
             {
                event.preventDefault();
                char val = event.getCharCode();
                char swapChar = val;
                String current = tf.getText();
                if (val == 'a')
                {
                   swapChar = '\u00E4';
                }
    
                tf.setText(current + swapChar);
             }
          });
          cp.setWidget(tf);
    
          RootPanel.get().add(cp);
       }
    }

  3. #2
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    Have you looked at TextField.addKeyPressHandler(...)?

  4. #3
    Sencha User ITS_luka's Avatar
    Join Date
    Aug 2011
    Location
    Tbilisi, Georgia
    Posts
    19
    Vote Rating
    0
    ITS_luka is on a distinguished road

      0  

    Default


    Yes, but its not as easy as it seems

  5. #4
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      1  

    Default


    Ah. It wasn't clear where you were at in your development. This works nicely, if however unreasonably specific. The key is event.preventDefault() since you don't want the original character rendering, without this line, both characters will render:

    Code:
    public class TextFieldKeyPressTest implements EntryPoint
    {
       @Override
       public void onModuleLoad()
       {
          ContentPanel cp = new ContentPanel();
          cp.setPixelSize(400, 400);
    
          final TextField tf = new TextField();
          tf.addKeyPressHandler(new KeyPressHandler()
          {
             @Override
             public void onKeyPress(KeyPressEvent event)
             {
                event.preventDefault();
                char val = event.getCharCode();
                char swapChar = val;
                String current = tf.getText();
                if (val == 'a')
                {
                   swapChar = '\u00E4';
                }
    
                tf.setText(current + swapChar);
             }
          });
          cp.setWidget(tf);
    
          RootPanel.get().add(cp);
       }
    }

  6. #5
    Sencha User ITS_luka's Avatar
    Join Date
    Aug 2011
    Location
    Tbilisi, Georgia
    Posts
    19
    Vote Rating
    0
    ITS_luka is on a distinguished road

      0  

    Default


    Thank you.

    Your reply helped me.

    but I have a question:

    what is the difference between setText()/getText() and setValue()/getValue() methods?

  7. #6
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    You're welcome. I believe get/set Value have to do with focus, i.e. getValue won't return the actual, displayed value (which is what getText does) until a blur event is fired.

    I attempted to verify this but getValue is always returning null because it appears that setText does not update the internal value reference. I am still working on this and don't have an answer yet.

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar