自定义控件-文本框获取焦点原创
金蝶云社区-吴锐雄
吴锐雄
2人赞赏了该文章 1,616次浏览 未经作者许可,禁止转载编辑于2021年06月08日 15:31:06


开发平台的文本框,在移动端中无法获取焦点,所以开发了一个自定义控件,在进入页面时,让当前文本框获取页面焦点。

原理是用js调用获取焦点的方法。


自定义控件方案,请查看附件。


本文章跳过前期创建页面,创建控件方案的步骤,如果想知道如果从零开始使用自定义控件,请参考其他文章:

https://vip.kingdee.com/article/150626162270913792


index.js

(function(KDApi) {

    function MyComponent(model) {
        this._setModel(model)
    }

    MyComponent.prototype = {
        _setModel: function(model) {
            this.model = model
        },
        init: function(props) {
            setHtml(this.model, props)
        },
        update: function(props) {
            setFocus()
        },
        destoryed: function() {}

    }


    /*
     * 外部函数声明
     */
    var setHtml = function(model, props) {

        KDApi.getTemplateStringByFilePath('./html/text.html', model, {})
            .then(function(result) {
                model.dom.innerHTML = result
                setFocus()
            })

    }

    function setFocus() {
        var t = document.getElementById('textfof')
        if (t !== null) {
            document.getElementById('textfof').focus()
        }
    }


    KDApi.register('textfof', MyComponent)

})(window.KDApi)


image.png

赞 2