PDA

View Full Version : How to pre-populate a Select menu UI item on Load of the Card (View)



mailboxo71
24 Mar 2011, 10:48 AM
Hi,

I like to know this, is there a way to pre-populate a Select menu UI item on Load of a Card that its in.

It like this, my app has a main menu that contains a button that pulls up the member settings card (screen) that contains a number of Select Menu UI items that I want to pre-populate with data from the database. Please let me know if thats possible and doable.

thanks in advance.

d5chris
24 Mar 2011, 2:02 PM
If you're using a Ext.form.Select, it has a 'store' property for just this purpose, so you should be able to do that. Eg set up a model and store to pull from your database, and bind the select to that store. Something like that...

mailboxo71
24 Mar 2011, 2:04 PM
Sounds easy enough but there's no sample code that actually shows how to do what you said. Especially from a Database.

Thanks anyway. but I do need sample codes

d5chris
24 Mar 2011, 2:09 PM
Sure:


Ext.regModel('MyOption', {
fields: [
{name: 'text', type: 'string'},
{name: 'value', type: 'string'}
]
});

var myStore = new Ext.data.Store({
model: 'MyOption',
proxy: {
type: 'ajax',
url : '/return-my-options-from-database.json.php',
reader: {
type: 'json',
root: 'users'
}
},
autoLoad: true
});
...
new Ext.form.Select({
store: myStore,
displayField: 'text', // This is the default and you could remove it
valueField: 'value' // Ditto
});

mailboxo71
24 Mar 2011, 2:26 PM
/// Here's my additional dilemma that I still need help.
/// There are like five select menus that will display all the same data from the store.

/// Here's the thing, each select menu will have a different selected item base on user settings store
in the database.

I can tell you now, the items are a list of neighborhoods and the each select menu will have a different
neighborhood pre-selected onLoad of the card.

I know how to do this in regular website in PHP, but I definately have trouble doing it with this framework.

d5chris
24 Mar 2011, 2:58 PM
That should be fine, simply have 5 selects all with store: myStore

mailboxo71
24 Mar 2011, 3:14 PM
///////////////////
//// My code does the rendering a little different.

I don't use this

new Ext.form.Select({
store: myStore,
displayField: 'text',
valueField: 'value'

});





Instead my select menus are specified by a FormPanel like so.


form = new Ext.form.FormPanel({
items: [
{
xtype: 'fieldset',
title: 'Edit Message Pref.',
instructions: 'Edit your Settings',
defaults: {
required: true,
labelAlign: 'left',
labelWidth: '40%'
},
items: [
{
xtype: 'fieldset',
title: 'General - Entire City',
items: [
{
xtype: 'checkboxfield',
Align: 'left',
name: 'cc0',
value: true
}

]
},


]

});






//// The problem is i don't instantiate the Ext.form.Select but instead specify as an item...

/// Is there a way to do the same thing as I have specify in my code...

Please note, I am using (xtype: 'selectfield')

d5chris
24 Mar 2011, 3:20 PM
Yes, the way you're doing it is more realistic: xtypes inside a formpanel. So you'd have something like:


form = new Ext.form.FormPanel({
items: [{
xtype: 'fieldset',
title: 'Edit Message Pref.',
instructions: 'Edit your Settings',
defaults: {
required: true,
labelAlign: 'left',
labelWidth: '40%'
},
items: [{
xtype: 'fieldset',
title: 'General - Entire City',
items: [{
xtype: 'checkboxfield',
Align: 'left',
name: 'cc0',
value: true
}, {
xtype: 'selectfield1',
store: myStore,
displayField: 'text',
valueField: 'value'
}, {
xtype: 'selectfield2',
store: myStore
}]
}]
}]
});

mailboxo71
25 Mar 2011, 7:30 AM
Here's my addtional dilemma,

In addtion to loading the options to the menus, I need to make the menus show the user's saved selection from the database. I don't know how to do the following.


1. How do I make a 2nd php call to retrieve the JSON. (I know how to write the PHP file that retrieves and spits out the JSON of the user's selection.

2. How do I parse the JSON receive and set the menu so it shows the user's saved selection of the menu.

In other words, when all the menus have loaded the options, I need the menu to show the user's saved selection of the menus.

I sincerely thank all the help.

Thanks