-
7 Dec 2011 2:42 PM #1
Answered: Change inputtext style in Textfield
Answered: Change inputtext style in Textfield
How can I change the testcolor of special textfields.
I can change it for every textfield with this
x-input-text {
color: red;
}
but i want it just for special texfields
with addCls() and removeCls()
thanks
-
Best Answer Posted by AndreaCammarata
Hi.
What you need to do to achieve that is to provide to the wanted textfields a custom "cls" config.
Take a look at the following example:
Then you need to define your "myCustomField" class in your application CSS as follows:Code:Ext.setup({ onReady: function() { var form = new Ext.form.FormPanel({ fullscreen: true, dockedItems: [{ xtype: 'toolbar', title: 'Example' }], items: [{ xtype: 'textfield', itemId: 'txtFirst', name : 'first', label: 'First name', cls: 'myCustomField' }] }); } });
This will give to all the textfields which have the same "cls" config, a red foreground color.Code:.x-field.myCustomField input { color: Red; }
If you want to change the color only on same particular events, you just need to add the same CSS class to the wanted textfields:
Hope this helps.Code:Ext.setup({ onReady: function() { var form = new Ext.form.FormPanel({ fullscreen: true, dockedItems: [{ xtype: 'toolbar', title: 'Example', items: [{ xtype: 'button', text: 'Change Color', handler: function(){ //Changing the textfield color form.getComponent('txtFirst').addCls('myCustomField'); } }] }], items: [{ xtype: 'textfield', itemId: 'txtFirst', name : 'first', label: 'First name' }] }); } });
-
9 Dec 2011 7:14 AM #2
Hi.
What you need to do to achieve that is to provide to the wanted textfields a custom "cls" config.
Take a look at the following example:
Then you need to define your "myCustomField" class in your application CSS as follows:Code:Ext.setup({ onReady: function() { var form = new Ext.form.FormPanel({ fullscreen: true, dockedItems: [{ xtype: 'toolbar', title: 'Example' }], items: [{ xtype: 'textfield', itemId: 'txtFirst', name : 'first', label: 'First name', cls: 'myCustomField' }] }); } });
This will give to all the textfields which have the same "cls" config, a red foreground color.Code:.x-field.myCustomField input { color: Red; }
If you want to change the color only on same particular events, you just need to add the same CSS class to the wanted textfields:
Hope this helps.Code:Ext.setup({ onReady: function() { var form = new Ext.form.FormPanel({ fullscreen: true, dockedItems: [{ xtype: 'toolbar', title: 'Example', items: [{ xtype: 'button', text: 'Change Color', handler: function(){ //Changing the textfield color form.getComponent('txtFirst').addCls('myCustomField'); } }] }], items: [{ xtype: 'textfield', itemId: 'txtFirst', name : 'first', label: 'First name' }] }); } });Sencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
9 Dec 2011 8:36 AM #3
Create that works fine.
Is there a way to give the Label two different colors ? like a cutline
for example "ABC-XYZ"
-
9 Dec 2011 8:40 AM #4
You can try to update the label element, for istance, in the following way:
Code:myField.labelEl.update('<span class="black">ABC-</span><span class="red">XYZ</span>');Sencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
9 Dec 2011 8:49 AM #5
Thanks Andrea, every thing is working

-
9 Dec 2011 8:53 AM #6
You are welcome
Sencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
9 Dec 2011 8:58 AM #7
Here the solution.
I do it now like this
Code:{ xtype: 'textfield', id: 'Zcard_textfield_ABC_XYZ_dp', name : 'ABC_XYZ_dp', label: 'ABC*-XYZ', listeners: { afterrender: function(ele) { ele.fieldEl.dom.readOnly = true; labelEl.update('<span class="font_red">ABC*-</span><span class="font_black">XYZ</span>'); } } }


Reply With Quote