1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    6
    Vote Rating
    0
    Answers
    1
    iooK is on a distinguished road

      0  

    Default Answered: Xml form and Ajax combobox, issue ?

    Answered: Xml form and Ajax combobox, issue ?


    Hello,


    I'm trying to select a value in combobox with xml form.
    I was inspired by this. http://dev.sencha.com/deploy/ext-4.0.../xml-form.html


    But in my case combobox loaded by ajax when a window is rendered.


    Code of combobox:
    Code:
    Ext.define('comboBoxLevel', {
    	extend: 'Ext.form.field.ComboBox',
    	alias: 'widget.comboBoxLevel',
    
    
    	allowBlank: false,
    	name: 'level_id',
    	fieldLabel: 'Level',
    	selectOnFocus: true,
    	displayField: 'WORD',
    	forceSelection: true,
    	queryMode: 'local',
    	store: 'levelForComboboxStore',
    	typeAhead: true,
    	typeAheadDelay: 50,
    		anchor: '100%',
    	valueField: 'ID',
            listeners: {
    			beforerender: function() {
    			this.store.load();
    		}
    	}
    	initComponent: function() {
    		var me = this;
    		me.callParent(arguments);
    	}
    });

    Code of combobox store:
    Code:
    Ext.define('levelForComboboxStore', {
    	extend: 'Ext.data.Store',
    	constructor: function(cfg) {
    		var me = this;
    		cfg = cfg || {};
    		me.callParent([Ext.apply({
    			storeId: 'levelForComboboxStore',
    			proxy: {
    				type: 'ajax',
    				pageParam: 'p',
    				url: '/ListLevelForComboBox',
    				reader: {
    					type: 'xml',
    					idProperty: 'ID',
    					totalProperty: 'totalProperty',
    					record: 'row'
    				}
    			},
    			fields: [
    				{mapping: 'ID', name: 'ID',type: 'int'},
    				{mapping: 'WORD', name: 'WORD',type: 'string'},
    				{mapping: 'FLAG', name: 'FLAG', type: 'string'}
    			]
    		}, cfg)]);
    	}
    });
    Example of xml:
    Code:
    <dataSet success="true">
    	<totalProperty>2</totalProperty>
    	<row>
    		<ID>1</ID>
    		<WORD>Level 0</WORD>
    		<FLAG>LEV0</FLAG>
    	</row>
    	<row>
    		<ID>2</ID>
    		<WORD>Level 1</WORD>
    		<FLAG>LEV1</FLAG>
    	</row>
    </dataSet>

    After this, I have a form with combobo in it.
    Form's inputs are completed with xml form.


    Model of reader
    Code:
    Ext.define('editUserModel', {
    	extend: 'Ext.data.Model',
    	fields: ['cli_id', 
    			{name: 'level_id', mapping: 'level_id', type: 'int'},
    			'user_firstname'
    	]
    });

    Xml for reader
    Code:
    <dataSet success="true">
    	<result>
    		<level_id>2</level_id>
    		<user_firstname>Doe</user_firstname>
    	</result>
    </dataSet>

    Text inputs work great but not combobox.
    Code:
    {
    	xtype: 'form',
    	frame: true,
    	reader : Ext.create('Ext.data.reader.Xml', {
    		model: 'editUserModel', 
    		record : 'result',
    		successProperty: '@success'
    	}),
    	items: [
    		{
    			xtype: 'textfield',
    			name: 'user_firstname',
    			fieldLabel: 'First name',
    			anchor: '100%'
    		},
    		{
    			xtype: 'comboBoxLevel',
    		}
    	]
    }



    When I load my xml form, text inputs are completed with good value, but combobox have no selection.
    I don't understand why ? Help me please?


    Regards.


    nb: Sorry for my poor english.

  2. Sorry, this code work.

    But you have to declare mapping in your fields of model...

  3. #2
    Sencha User
    Join Date
    Feb 2011
    Posts
    6
    Vote Rating
    0
    Answers
    1
    iooK is on a distinguished road

      0  

    Default


    Sorry, this code work.

    But you have to declare mapping in your fields of model...