diff --git a/cocos2d/core/components/CCEditBox.js b/cocos2d/core/components/CCEditBox.js index 1f3dc2ab4f..2e988d0ca4 100644 --- a/cocos2d/core/components/CCEditBox.js +++ b/cocos2d/core/components/CCEditBox.js @@ -341,7 +341,11 @@ var EditBox = cc.Class({ /** * !#en The maximize input length of EditBox. + * - If pass a value less than 0, it won't limit the input number of characters. + * - If pass 0, it doesn't allow input any characters. * !#zh 输入框最大允许输入的字符个数。 + * - 如果值为小于 0 的值,则不会限制输入字符个数。 + * - 如果值为 0,则不允许用户进行任何输入。 * @property {Number} maxLength */ maxLength: { diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js index 6f74651f5d..822935536c 100644 --- a/cocos2d/core/editbox/CCSGEditBox.js +++ b/cocos2d/core/editbox/CCSGEditBox.js @@ -390,7 +390,12 @@ _ccsg.EditBox = _ccsg.Node.extend({ }, setMaxLength: function (maxLength) { - if (!isNaN(maxLength) && maxLength > 0) { + if (!isNaN(maxLength)) { + if(maxLength < 0) { + //we can't set Number.MAX_VALUE to input's maxLength property + //so we use a magic number here, it should works at most use cases. + maxLength = 65535; + } this._maxLength = maxLength; this._renderCmd.setMaxLength(maxLength); } diff --git a/jsb/jsb-editbox.js b/jsb/jsb-editbox.js index 4db8a9aa8f..581149e1ca 100644 --- a/jsb/jsb-editbox.js +++ b/jsb/jsb-editbox.js @@ -26,6 +26,15 @@ 'use strict'; var _p = cc.EditBox.prototype; + +_p._setMaxLength = _p.setMaxLength; +_p.setMaxLength = function(maxLength) { + if (maxLength < 0) { + maxLength = 65535; + } + this._setMaxLength(maxLength); +}; + cc.defineGetterSetter(_p, 'font', null, _p.setFont); cc.defineGetterSetter(_p, 'fontName', null, _p.setFontName); cc.defineGetterSetter(_p, 'fontSize', null, _p.setFontSize); @@ -42,17 +51,9 @@ cc.defineGetterSetter(_p, 'delegate', null, _p.setDelegate); cc.defineGetterSetter(_p, 'inputMode', null, _p.setInputMode); cc.defineGetterSetter(_p, 'returnType', null, _p.setReturnType); -_p._setMaxLength = _p.setMaxLength; -_p.setMaxLength = function(maxLength) { - if (maxLength == -1) { - maxLength = Number.MAX_VALUE; - } - this._setMaxLength(maxLength); -}; _p.setLineHeight = function () {}; - _p.setTabIndex = function () {}; _p.getTabIndex = function () { return -1; }; _p.setFocus = function () {};