Reputation:
I have a text field and a displayfield. I want the user value of the text field to displayed in the display field. how do i do that?
My code is as follows:
{
xtype: 'textfield',
fieldLabel: 'Textfield',
allowblank: false
}, {
xtype: 'displayfield',
fieldLabel: 'Textfield Value',
value: 'textfieldValue'
}
Upvotes: 0
Views: 2197
Reputation: 20224
The fastest implementation would be a listener on the textfield:
listeners: {
change: function(field, newValue) {
field.nextSibling().setValue(newValue)
}
}
Or you use a viewModel on the parent container and bind the value, this improves reusability:
xtype:'panel',
viewModel:{
},
items:[{
xtype: 'textfield',
fieldLabel: 'Textfield',
allowBlank: false,
bind: {
value: '{value}'
}
},{
xtype: 'displayfield',
fieldLabel: 'Textfield Value',
bind: {
value: '{value}'
}
}]
A fiddle with both implementations: https://fiddle.sencha.com/#view/editor&fiddle/206o
Upvotes: 4