View Full Version : Alignment of icon next to textfield control

3 Sep 2012, 4:04 AM
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.

<style type="text/css">

.icon {
background-image: url("../Content/images/not_documented.png");
cursor: pointer;
height: 16px;
width: 16px;

<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 () {
afterRender: function () {
if (this.iconCls) {
var iconCls = this.iconCls;
//delete this.iconCls;


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.iconCls = iconCls;
this.icon.dom.className = iconCls;
//this.icon.alignTo(this.el, 'tl-tr', [2, 0]);
listeners: {
change: function (obj, newValue) {

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() {
}, {
text: 'Submit',
formBind: true, //only enabled once the form is valid
disabled: true,
handler: function() {
var form = this.up('form').getForm();
if (form.isValid()) {
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.

17 Sep 2012, 6:33 AM
Have you checked out how the error icon works?