Problem with EditBox!

Hi all, i have somes problems with EditBox:

  • When finished type, how to call a function after pressing Enter
  • How to change focus of next EditBox when press Tab

Please help me resolve.
Thanks

There is an example show how to use the EditBox :

You can specify the callback in the inspector like this:

I used 3 above events. Event editing Edit Ended fire when i press any keyboard :frowning:

This is my test in simulator and chrome.
‘editBoxDidEndEditing’ only fired when EditBox lost focus.

Simulator : 01_Single_Line_EditBox single line editBoxDidBeginEditing
Simulator : 01_Single_Line_EditBox single line editBoxDidChanged: d
Simulator : 01_Single_Line_EditBox single line editBoxDidChanged: dd
Simulator : 01_Single_Line_EditBox single line editBoxDidChanged: ddd
Simulator : 01_Single_Line_EditBox single line editBoxDidChanged: dddd
Simulator : 01_Single_Line_EditBox single line editBoxDidChanged: ddddd
Simulator : 01_Single_Line_EditBox single line editBoxDidChanged: dddddd
Simulator : 01_Single_Line_EditBox single line editBoxDidChanged: ddddddd
Simulator : 01_Single_Line_EditBox single line editBoxDidEndEditing: ddddddd

Yes. But i just want fire event when i press Enter keyboard.

For keyboard event please use:

cc.eventManager.addListener({
    event: cc.EventListener.KEYBOARD,
    onKeyPressed: function (key, event) {
        cc.log("Key down:" + key);
    },
    onKeyReleased: function (key, event) {
        cc.log("Key release:" + key);
    }
}, this.node);

For key value you can compare with cc.key

This event not fire when i focus in EditBox. I cheked and see EditBox is input html

I see, then you might need to detect onkeypress event of the input element

2 Likes

Thank’s you very much. I did it

how you did that?