How to check if value entered in to the EditBox?

Hi.

So I have an EditBox in my project and I would like to run some code when a value has been entered in to the edit box and the player pressed the return button on keyboard.

I’ve been trying to use the Editing Did Ended and Editing Return callback functions, and both do what I need in web platform in the browser, but on native desktop platform I need to click outside the box for it to lose focus to make the event execute and this is not what I want.

I was searching the forum and read docs, but I can’t find any other ways to go about this but Editing Did Ended and Editing Return callbacks but they don’t work as I expected on native platform.

If nothing else, I can add an Enter button and evaluate the value in the box only if the Enter button was pressed, but I am wondering if is there any other ways to check if value was entered in to the box?
I would like the player to be able to just enter the value in to the box, press Return on keyboard and done. I prefer not to force the player to click on an additional button in the scene.
Is there any solution to this?

Using Cocos Creator 2.4.3 on macOS

Demo:
EditBoxTest.zip (833.2 KB)

Thanks.

editing-did-eneded event should work
Can’t you use editing-did-eneded event when you press the ‘done’ button on the soft keyboard ?

Is that problem appears on Android, or iOS platform ?

In the web browser it is works on all platforms including mobile.
I did not try native iOS and Android builds.
In the simulator and native macOS build, it does not work. I need to click outside the edit box to make it trigger.

One possible work around I was considering is to check if the enter key is down on the keyboard and then check if the editbox has any value, but unfortunately as long the editbox is in focus, the KEY_DOWN system event does not trigger and I can’t find any method to force the editbox to lose focus.

Got it, it does have this problem on macOS or win32 platform
we’ll check if it can be solved on the next version v2.4.4

1 Like