Setting editbox string onTextChanged

I want to edit the string inside editbox right after textchanged when editbox is still in focus. The following code works in 1.10
onTextChanged: function(string, editbox) {
editbox.string = “something”;
}

However in 2.2.0, the display of editbox while in focus does not change with the code, instead it changes AFTER it is blurred. The current way I am using is to blur the editbox then focus it again (with a scheduler to delay 0.1s), but I would like to know if any cleaner way to make it work like it used to.

I’ve also dealed with that, and I’ve managed to do it like this (on web):

  • The input is an input html element so first found the current input (the visible one)
            var input = document.getElementsByClassName('cocosEditBox');
            for (let i = 0; i < input.length; i++) {
                const element = input[i];
                if (element.style.display != 'none') {
                    input = element;
                    break;
                }
            }
  • Set the value to the input element

input.value = ‘anything’;

  • Set the string to the cocos editbox

this.editBox.string = input.value;

Hope this helps… I don’t know if this works on native…

Surely it cannot work on native because native cannot access DOM elements, but still it looks fine enough on web