PDA

View Full Version : Checkbox group BULK LOAD



Bob Wilson
9 Jun 2012, 2:39 AM
Hi all,

I've been searching for a simple solution to bulk load my checkboxgroup values from an Ajax request using EXTJS 4.1, but, damn...

I found this irritating post (talking about radio group, but it's about the same kind of "pair-valued" object)
http://extjs-tutorials.blogspot.com/2011/12/ext-js-radiogroup.html
(http://extjs-tutorials.blogspot.com/2011/12/ext-js-radiogroup.html)
Honestly, I can't believe that Ext can do highly complicated things, and cannot do the simplest ones.:-?

To load simple objects, the JSON returned by the server should be like this, according to the API doc :



success:true,
data:{
clientName:"Fred. Olsen Lines",
portOfLoading:"FXT",
portOfDischarge:"OSL"
}


But for an array object like a checkbox group containing, for example, "A", "B" and "C" values, what is the correct JSON response syntax if my database has the values "A" and "B" stored ?

I've tried a lot of combinations... like :


data:{
mycheckboxgroupmame: [{"A": "checked"}, {"B": "checked"}]
}


Not working...8-|



data: {
mycheckboxgroupname: [
{boxLabel: "A", "checked": true},
{boxLabel: "B", "checked": true}
]
}


Not working...:s



data: {
mycheckboxgroupname: ["A","B"]
}


Not working...:((

Well... I will not post here all the combinations I've tried, with quotes, without quotes, using "value" parameter instaed of "checked", and a lot, yes, really a lot of other tries.

So, just one question : is it possible to use the basic form load() method to load checkboxgroup values ?

mitchellsimoens
11 Jun 2012, 7:09 AM
Here is a testcase I tested on 4.0.7 and 4.1.1 RC1 that loads the values for a CheckboxGroup:


new Ext.form.Panel({
renderTo : document.body,
width : 400,
items : [
{
xtype : 'checkboxgroup',
fieldLabel : 'Checkbox Group',
items : [
{ boxLabel : 'One', name : 'cb', inputValue : '1' },
{ boxLabel : 'Two', name : 'cb', inputValue : '2' },
{ boxLabel : 'Three', name : 'cb', inputValue : '3' },
{ boxLabel : 'Four', name : 'cb', inputValue : '4' },
{ boxLabel : 'Five', name : 'cb', inputValue : '5' }
]
},
{
xtype : 'button',
text : 'Load',
handler : function(button) {
var form = button.up('form');

form.load({
url : 'data/json.json'
});
}
}
]
});

data/json.json:


{
"success": true,
"data": {
"cb": [
"1",
"3",
"4"
]
}
}

Is this what you were asking about?

Bob Wilson
11 Jun 2012, 12:27 PM
Thank you very much... I had 2 problems and you solved one of them : thank you very much.

Problem 1)
I've passed over my mistake about one hundred times without seeing it.
The server response must mention the CHECKBOX name, and not the CHECKBOXGROUP name.

Still, this sounds like a weird strategy, because it prevents different checkboxes to store the same value.
What happens if you have something like this in your checkbox group ?



{ boxLabel : 'Coffee', name : 'cb', inputValue : '1' },
{ boxLabel : 'Tea', name : 'cb', inputValue : '2' },
{ boxLabel : 'Coke', name : 'cb', inputValue : '1' },
{ boxLabel : 'Apple Juice', name : 'cb', inputValue : '2' },
{ boxLabel : 'Custom soda', name : 'cb', inputValue : '1' }


... with a server response like this :


data: {"cb": ["1", "1"]}



Problem 2)
In my real app, my field was called "data_", and it seems it is a reserved keyword or something...
Maybe too close of the "data" tag used by Ext parser ?

The problem disappeared when I changed it to dataX (X instead of underscore).


Anyway, you helped me a lot with your working example. Thanks again.

mitchellsimoens
11 Jun 2012, 12:34 PM
Problem 1: I'm thinking it will check any checkbox with the value so if you have 3 checkboxes with inputValue = '1' it should check all 3. Simple to test.

Problem 2: I'm thinking the underscore at the end is throwing it off. Being close to data isn't an issue, it checks the name with ===