1. #1
    Sencha User
    Join Date
    Nov 2010
    Posts
    47
    Vote Rating
    0
    nil5286 is on a distinguished road

      0  

    Default Unanswered: Alignment of icon next to textfield control

    Unanswered: Alignment of icon next to textfield control


    I want the icon on right side of textfield , What i am trying is i wrap the textbox and that wrapper has relative position and then to this wrap i append a div with absolute position and then set the class to it to show the icon. My question is the icon with the absolute position shouldn't it sit within the relative positioned wrapper. I see the wrapper and icon div outside of the textfield table in the HTML tab of firebug after it is rendered. My code with the screen shot is as below.

    Code:
        <style type="text/css">
            
            .icon {
                background-image: url("../Content/images/not_documented.png");
                cursor: pointer;
                height: 16px;            
                width: 16px;            
            }
            
        </style>
            <script type="text/javascript">
    
        Ext.onReady(function () {
    
            //define a new custom text field
            Ext.define('WithStatusTextField', {
                extend: 'Ext.form.field.Text',
                alias: 'widget.withStatusTextField',
                iconCls: 'icon ',
                fieldStyle: {
                    textTransform: "uppercase"
                },
                initComponent: function () {
                    this.callParent(arguments);
                },
                afterRender: function () {
                    if (this.iconCls) {
                        var iconCls = this.iconCls;
                        //delete this.iconCls;
                        this.setIconCls(iconCls);
                    }
                    this.callParent(arguments);
    
                },
    
                renderIconEl: function () {
                    if (!this.wrap) {
                        this.wrap = this.el.wrap({ cls: "x-form-field-wrap" });
                        this.positionEl = this.wrap;
                    }
                    
                    this.wrap.applyStyles({ position: "relative" });
    
                    this.icon = Ext.DomHelper.append(this.el.up("div.x-form-field-wrap") || this.wrap, 
                    {
                        tag: "div",
                        style: "position:absolute"
                    }, true)
                    if (!this.width) {
                        this.wrap.setWidth(this.el.getWidth() + 50);
                    }
                    this.icon.on("click", function (e, t) {
                        this.fireEvent("iconclick", this, e, t);
                    }, this);
                },
                setIconCls: function (iconCls) {
                    if (this.iconCls) {
                        this.renderIconEl();
                    }
                    this.iconCls = iconCls;
                    this.icon.dom.className = iconCls;
                    //this.icon.alignTo(this.el, 'tl-tr', [2, 0]);
                },
                listeners: {
                    change: function (obj, newValue) {
                        console.log(newValue);
                        obj.setRawValue(newValue.toUpperCase());
                    }
                }
            });
    
            Ext.create('Ext.form.Panel', {
                title: 'Simple Form',
                bodyPadding: 5,
                width: 350,
                height: 150,
    
                // The fields
                defaultType: 'withStatusTextField',
                items: [{
                    fieldLabel: 'First Name',
                    name: 'first',
                    allowBlank: false                
                },{
                    fieldLabel: 'Last Name',
                    name: 'last',
                    allowBlank: false
                }],
    
                // Reset and Submit buttons
                buttons: [{
                    text: 'Reset',
                    handler: function() {
                        this.up('form').getForm().reset();
                    }
                }, {
                    text: 'Submit',
                    formBind: true, //only enabled once the form is valid
                    disabled: true,
                    handler: function() {
                        var form = this.up('form').getForm();
                        if (form.isValid()) {
                            form.submit({
                                success: function(form, action) {
                                   Ext.Msg.alert('Success', action.result.msg);
                                },
                                failure: function(form, action) {
                                    Ext.Msg.alert('Failed', action.result.msg);
                                }
                            });
                        }
                    }
                }],
                renderTo: Ext.getBody()
            });
    when i put the debug point in firebug at the point where the class for the div that show the icon is set it shows the icon properly next to the textfield the screenshot of which is but after the complete render the icon sits somewhere else.

    Wrap on textfield with icon class afterRender - the visual display of icon after the icon class is set.

    Wrap on textfield with icon class - this.wrap.dom.outerHtml

    dom Structure - after the complete render the div icon class with field wrap class goes outside the textfield div.
    Attached Images

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Answers
    3541
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Have you checked out how the error icon works?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread