user4475435
user4475435

Reputation:

Display value of textfield in displayfield

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

Answers (1)

Alexander
Alexander

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

Related Questions