mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Merge pull request #1184 from zilongshanren/fix-issue-3959
improve editbox maxLength settings
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+9
-8
@@ -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 () {};
|
||||
|
||||
Reference in New Issue
Block a user