cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.22k stars 7.06k forks source link

Error in UITextField on mobile devices #15019

Open ppawlak opened 8 years ago

ppawlak commented 8 years ago

Using Cocos2d-JS v3.10, I had errors on some mobile devices with the UITextField component.

First error:

TypeError: Cannot read property 'call' of undefined
at apply(../../frameworks/cocos2d-html5/extensions/ccui/uiwidgets/UITextField.js:489:16)
  at attachWithIME(../../frameworks/cocos2d-html5/cocos2d/text-input/CCTextFieldTTF.js:324:15)
  at attachDelegateWithIME(../../frameworks/cocos2d-html5/cocos2d/text-input/CCIMEDispatcher.js:372:12)
  at _focusDomInput(../../frameworks/cocos2d-html5/cocos2d/text-input/CCIMEDispatcher.js:395:28)

this happens with this User-Agent Mozilla/5.0 (Linux; Android 4.2.2; GT-S7275R Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.95 Mobile Safari/537.36

Second error:

TypeError: Window.prototype.prompt is undefined
  at func(../../frameworks/cocos2d-html5/extensions/ccui/uiwidgets/UITextField.js:489:16)
  at self(../../frameworks/cocos2d-html5/cocos2d/text-input/CCTextFieldTTF.js:324:15)
  at cc(../../frameworks/cocos2d-html5/cocos2d/text-input/CCIMEDispatcher.js:372:12)
  at _focusDomInput(../../frameworks/cocos2d-html5/cocos2d/text-input/CCIMEDispatcher.js:395:16)

this happens with this User-Agent
Mozilla/5.0 (Android 4.1.1; Mobile; rv:44.0) Gecko/44.0 Firefox/44.0

ppawlak commented 8 years ago

I have been told by people experiencing those errors that the virtual keyboard on their device is not popping up, and are therefore unable to input text.

jramstedt commented 8 years ago

changing

if(window.Window && Window.prototype.prompt != prompt){
   userInput = Window.prototype.prompt.call(window, tipMessage, this._currentInputString);
}else{
    userInput = prompt(tipMessage, this._currentInputString);
}

to


var realPrompt = prompt || window.prompt || Window.prototype.prompt;
var userInput = realPrompt(tipMessage, this._currentInputString);

fixes the problem.