How to add tooltip to text form field in extjs6

别等时光非礼了梦想. 提交于 2019-12-11 13:17:59

问题


I have function for creating/rendering input fields but i don't know how to add tool tip on it in EXTjs6

this is my function:

createInputField: function(value, fieldsMarginBottom, readonly) {
        var fieldStyle = this.getFieldStyle(readonly);
        var nameField = Ext.create('Ext.form.field.Text', {
            name: 'name',
            readOnly: true,
            hideLabel: true,
            value: value,
            width: this.fieldWidth,
            style: {
                marginBottom: fieldsMarginBottom + 'px'
            },
            //My try which is not working
            tooltip: {
                trackMouse: true,
                width: 140,
                renderer: function(tip, item){
                    tip.setTitle('name');
                    tip.update('Count: ');
                }
            },
            fieldStyle: fieldStyle
        });
        return nameField;
    }

I hope you guys can help me. If you need any additional informations, please let me know and I'll provide. Thank you


回答1:


As can be seen in the textfield docs, fields do not have a way to add a tooltip to their configuration, so you would have to create the tooltip manually.

If you look at the docs for Ext.tip.ToolTip how to do that, you may find a small example, where you just have to change the target as per the target configuration description:

var tip = Ext.create('Ext.tip.ToolTip', {
    target: nameField.getEl(),
    html: 'Press this button to clear the form'
});



回答2:


Above answer is correct. Here is example of generic function which you write once and use wherever you required in project by using using attributes.

addToolTip : function (id, msg) {
    new Ext.ToolTip({
            target : id,
            dismissDelay : 0,
            anchor : 'right',
            html : msg
        });
};


来源:https://stackoverflow.com/questions/38300286/how-to-add-tooltip-to-text-form-field-in-extjs6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!