PDA

View Full Version : Refresh Label Text



Cougar84
17 Apr 2012, 1:04 AM
Hi,
I've a question about how to refresh Labels text of an entire form with one instruction ...

For example, this is my panel:



Ext.create("Ext.panel.Panel", {
items: [{
name: 'lblMessaggio',
xtype: 'label',
margins: '5 0 15 0',
text: IA.Labels.login.msg.standard,
cls: 'labelGray',
style: 'text-align: center;'
},{
xtype: 'combobox',
name : 'cboSoc',
stateId: 'cboSoc',
fieldLabel: IA.Labels.login.societa,
store: 'Societa',
valueField: 'CodSoc',
displayField: 'DesSoc',
queryMode: 'local',
allowBlank: true,
editable: false,
submitValue: true
},{
xtype: 'textfield',
name : 'txtUser',
stateId: 'txtUser',
fieldLabel: IA.Labels.login.user,
maxLength: 30,
enforceMaxLength: true,
allowBlank: false
}, {
xtype: 'textfield',
name : 'txtPassword',
stateId: 'txtPassword',
fieldLabel: IA.Labels.login.password,
maxLength: 30,
enforceMaxLength: true,
inputType: 'password',
allowBlank: true
}
],


bbar: [
{
name: 'cmdAssistenza',
iconCls: 'assistenza_Icon',
scale: 'large',
text: IA.Labels.login.buttons.assistenza
},{
name: 'cmdRecuperaPassword',
iconCls: 'chiave_Icon',
scale: 'large',
text: IA.Labels.login.buttons.recupera
}
]
}

After loading this form the IA.Labels is loaded with Italian text ...
I made a language change ( ex. Franch ) with the panel always open.
The IA.Labels is reloaded with a Ext.Ajax.request and an eval and the correct Franch text are loaded.

But in the panel the labels doesn't change ( of course ) ...
But how can I refresh all the labels with a single shot?

Thanks to all,
Marco

scottmartin
17 Apr 2012, 5:36 AM
You would have to use setFieldLabel( String label ) to change existing labels. There is no 1 command to do this.

Please have a look at our dynamic localization example for info that may help:
http://dev.sencha.com/deploy/ext-4.0.7-gpl/examples/locale/multi-lang.html

Regards,
Scott.

Cougar84
17 Apr 2012, 5:40 AM
I'm using the Localization example but there to change the current labels it refresh the page ...

scottmartin
17 Apr 2012, 6:10 AM
As mentioned, you can use setFieldLabel() to change the value:

Just create a function that updates the field types of the form from your array.



Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
id: 'namefield', // using id for demo
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
allowBlank: false // requires a non-empty value
}, {
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email Address',
vtype: 'email' // requires value to be a valid email address format
}]
});

Ext.create('Ext.Button', {
text: 'Change Label',
renderTo: Ext.getBody(),
handler: function() {
var nf = Ext.getCmp('namefield');
nf.setFieldLabel('New label');

}
});


Regards,
Scott.