patryks
patryks

Reputation: 692

ExtJs TextField with small button

How to create small button with icon inside textfield, like with datefield? In previous version of ExtJS there was a CompositeField but cant find it in ExtJS 4.

Upvotes: 11

Views: 11649

Answers (2)

Ruan Mendes
Ruan Mendes

Reputation: 92274

Just extend http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.Trigger You can change the icon of the trigger field with CSS and implement the behavior of clicking the icon in the onTriggerClick template method

Ext.define('Ext.ux.CustomTrigger', {
    extend: 'Ext.form.field.Trigger',
    alias: 'widget.customtrigger',

    // override onTriggerClick
    onTriggerClick: function() {
        Ext.Msg.alert('Status', 'You clicked my trigger!');
    }
});

Ext.create('Ext.form.FormPanel', {
    title: 'Form with TriggerField',
    renderTo: Ext.getBody(),
    items:[{
        xtype: 'customtrigger',
        fieldLabel: 'Sample Trigger',
        emptyText: 'click the trigger'
    }]
});

Upvotes: 13

Sean Adkinson
Sean Adkinson

Reputation: 8605

Is the icon clickable? If so, you are looking for Ext.form.field.Trigger. If not, you might try overriding the Text field's getSubTplMarkup() function to provide some custom dom.

For example:

Ext.define('MyField', {
    extend: 'Ext.form.field.Text',

    getSubTplMarkup: function() {
        return this.callParent(arguments) + '<span class="my-icon"></span>';
    }
});

Upvotes: 6

Related Questions