Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS 4: Is there any way to attach a QuickTip to a form field?

Tags:

extjs

extjs4

I'm trying to add a QuickTip to a form field, but can't find a way to make my code work. Firstly, I tried to use a qtip attribute

    {
        fieldLabel: 'Last Name',
        qtip:'This tip is not showing at all',
        name: 'last'
    }

and then using Ext.tip.ToolTip class:

Ext.create('Ext.tip.ToolTip', {
    target: 'rating_field',
    anchor: 'right',
    trackMouse: true,
    html: 'This tip is not showing at all'
});

Ext.QuickTips.init();

Here is a jsfiddle with the source code: jsfiddle

like image 434
cansadadeserfeliz Avatar asked Aug 14 '13 19:08

cansadadeserfeliz


3 Answers

Yes, use the inputAttrTpl config and the data-qtip attribute:

{
    fieldLabel: 'Last Name',
    inputAttrTpl: " data-qtip='This is my quick tip!' ",
    name: 'last'
}
like image 171
Reimius Avatar answered Nov 02 '22 04:11

Reimius


I found the answer here: How should I add a tooltip to an ExtJS Component?

    {
        fieldLabel: 'Last Name',
        qtip: "This is a tip",
        name: 'last',
        listeners: {
            render: function(c) {
                Ext.QuickTips.register({
                    target: c.getEl(),
                    text: c.qtip
                });
            }
        }
    }
like image 8
cansadadeserfeliz Avatar answered Nov 02 '22 02:11

cansadadeserfeliz


Using vero4ka's answer I wrote a simple plugin which can be used with forms to enable quicktips on child fields.

Ext.define('Ext.form.QtipPlugin', {
    extend: 'Ext.AbstractPlugin',

    alias: 'plugin.qtipfields',

    init: function (cmp) {
        this.setCmp(cmp);

        cmp.on('beforerender', function () {

            var fields = cmp.query('field[qtip]');

            for (var i = 0; i < fields.length; i++) {

                fields[i].on('render', this.register, this);

            }

        }, this);
    },

    register: function (field) {
        var obj = {
            target: field.id
        };

        if (typeof field.qtip === 'string') {
            obj.text = field.qtip;
        } else if (typeof field.qtip === 'object') {
            // Allow qtip configuration objects.
            // i.e. qtip: { text: 'hi', ... }
            Ext.applyIf(obj, field.qtip);
        }

        Ext.tip.QuickTipManager.register(obj);
    }
});
like image 4
Will S Avatar answered Nov 02 '22 03:11

Will S