View Full Version : Populate checkbox from JSON data?

4 Jul 2007, 10:50 AM
I was looking for a way to simulate a 'multiple select' on a form as I found out that this control (SELECT MULTIPLE) is not yet implemented.
Found some tricks on how to do this which I like most the one using checkboxes insted of a multi select control (http://extjs.com/forum/showthread.php?t=5262&highlight=multiple+select&page=2).
My problem is how can I generate my checkboxes list from a JSON record (I know how JSON works, just not sure how to use it with checkboxes). Also in order to send the selected checkboxes back to server, wich is the best way to do this....iterate through the whole checkboxes and create a JSON with the selected ones or is there a simpler (elegant) way to do it?
Thanks for your time ;)

P.S. If someone found a better way to deal with multiple selections (HTML SELECT MULTI) I will be happy to read about it.

5 Jul 2007, 12:36 PM
I am using the following code (if you didn't really understood my question):

var dsLang;

dsLang= new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'get_lang.php'}),

reader: new Ext.data.JsonReader({root: 'results',id: 'id'},
{name: 'id', mapping: 'id'},
{name: 'lang', mapping: 'lang'}



for (i=1; i<dsLang.getCount(); i++)

var limbi_show = new Ext.form.Checkbox({
boxLabel: dsLang.data.items[i].lang,
checked: false,
name: 'lang'+Ext.Id(), //is there another way to auto generate unique IDs for this?
inputValue: dsLang.data.items[i].lang

What I want to do is to diplay a list (like a select box wich allows multiple selections) with the languages from a JSON data.