简体   繁体   中英

How to populate a textfield with the value from a list selection in Sencha Touch?

I have a textfield and I have a list. I want to populate the textfield with the record from a list selection. How can I make this happen? I'm doing the application in Sencha Touch.

Here is my list code:

var airports = new Ext.List({
    fullscreen: true,
    id: 'list',
    indexBar: false,
    itemTpl : '{firstName} {lastName}',
    listeners:{
       change: function() {
        var el = Ext.getDom('from'); 
        el.setValue(this.getValue())
       }

    },
    store: store

});

And here is my textfield code:

{
    xtype: 'textfield',
    name : 'from',
    label: 'From',
    id: 'from',
    labelWidth: '23%',
    placeHolder: 'Search airport',
    readOnly : true,
    listeners: {'render': function(cmp) { 
            cmp.getEl().on('click', function( event, el ) {
                                NotiflyApp.views.viewport.setActiveItem('ListContainer', {type: 'fade'});
            });            
    }}
},

Okey, so I managed to solve it by reading this tutorial .

Here is the list code:

var fromAirports = new Ext.List({
    fullscreen: true,
    id: 'airportList',
    indexBar: false,
    itemTpl : '{airport} {IATAcode}',
    onItemTap: function(item, index) {
    var formField = NotiflyApp.views.formField;
    var selectedAirport = store.getAt(index).get('firstName');
    var selectedIATA = store.getAt(index).get('lastName');
    var from = Ext.ModelMgr.create(
        { from: selectedAirport + ' ' + selectedIATA }, 'Contact');
        NotiflyApp.views.formField.load(from);
        NotiflyApp.views.viewport.setActiveItem('formInput', {type: 'fade'});
        },

    store: store
});

Hope this helps! If you have problems implementing it please comment and I'll try to help you out!

I have the same as you ( I guess) - a list and a form - where I want to fill the fields with the items of my list

If is that what you want you can try this in a function onItemDisclosure:

      var dataName= record.store.data.getAt(index).data.dataName;
      var dataSurname= record.store.data.getAt(index).data.dataSurname;

Then in the form field you can try:

      Ext.getCmp('name').setValue(dataName);
      Ext.getCmp('surname').setValue(dataSurname);

I don't know if it's some kind of a big workaround but it worked for me:) I hope I could help!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM