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

6

10

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

Dannie answered 14/8, 2013 at 19:59 Comment(0)
A
24

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

{
    fieldLabel: 'Last Name',
    inputAttrTpl: " data-qtip='This is my quick tip!' ",
    name: 'last'
}
Aquatint answered 14/8, 2013 at 22:6 Comment(3)
With this method there's no optical indicator that shows that the form field provides a quick tip. Is there an easy way to add an icon if a quick tip is present?Bicuspid
I do not believe there is a very easy way, but you could add some CSS to change the field border or something with the appropriate configuration optionAquatint
that looks seriously ugly. Why can't they just have "qTip: 'my quicktip'"... mehRelay
D
8

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
                });
            }
        }
    }
Dannie answered 15/8, 2013 at 16:10 Comment(1)
To clarify. I'd like to point out that while this works, it's just a roundabout way to do the same thing. All registering with "Ext.QuickTips.register" does is add the data-qtip attribute to the html. The only real reason to use this way instead is if you want an easier way to escape html with dynamically created qtips.Aquatint
A
4

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);
    }
});
Augustaaugustan answered 8/4, 2015 at 15:23 Comment(0)
D
3

For any form field, you can use this:

{
    xtype: 'textfield', // or anything else
    autoEl: {
        'data-qtip': 'This is working tip!'
    }
}
Dematerialize answered 18/5, 2017 at 10:12 Comment(1)
This worked for adding a tip to a radiogroup item. {boxLabel: 'Flat Rate', name: 'rate_type', inputValue: 1, autoEl: {'data-qtip': 'One rate regardless of usage.'}},Chauffer
G
0

You can also use the built-in plugin datatip on a form panel. in form panel (see http://docs.sencha.com/extjs/6.5.1/classic/Ext.ux.DataTip.html) :

in form config :

plugins = [{ptype : 'datatip'}]

in field text config :

tooltip : "my tooltip text"
Glee answered 7/9, 2017 at 10:12 Comment(0)
B
0

If you are generating tooltip dynamically then you can use below snippet:

txtFieldName.el.set({ "data-qtip": Ext.String.htmlDecode("Some Text") });
Brighton answered 29/1, 2018 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.