Editbox组件,max length失效

  • Creator 版本:2.3.3

  • 目标平台: web

  • Editbox组件,当input mode选择了NUMERIC,maxlength失效,可以无限制输入字符

经过确认,原来 H5 input 标签本身是无法通过 maxLength 属性限制 number 类型的字符输入的。
:sweat_smile:
感兴趣的可以,在菜鸟教程上测试下:
https://www.runoob.com/html/html5-form-input-types.html

现在方案是自己加个监听回调处理下:

// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {
        
    }

    inputValueHandle (value: string, editbox: cc.EditBox) {
        editbox._impl._elem.value = editbox.string;
    }
    // update (dt) {}
}

引擎也会修复这个问题。

2赞

可以参考这个 pr 修复
https://github.com/cocos-creator/engine/pull/6725

1赞