1. #1
    Sencha User
    Join Date
    Sep 2010
    Posts
    56
    Vote Rating
    1
    Bob Wilson is on a distinguished road

      0  

    Default Answered: Checkbox group BULK LOAD

    Answered: Checkbox group BULK LOAD


    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

    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 :

    Code:
    
    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 :
    Code:
    data:{
            mycheckboxgroupmame: [{"A": "checked"}, {"B": "checked"}]
    }
    
    Not working...

    Code:
    data: {
            mycheckboxgroupname: [
                {boxLabel: "A", "checked": true},
                 {boxLabel: "B", "checked": true}
            ]
        }
    
    Not working...

    Code:
    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 ?
    Last edited by Bob Wilson; 9 Jun 2012 at 2:45 AM. Reason: Code tags missing

  2. Here is a testcase I tested on 4.0.7 and 4.1.1 RC1 that loads the values for a CheckboxGroup:

    Code:
    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:

    Code:
    {
        "success": true,
        "data": {
            "cb": [
                "1",
                "3",
                "4"
            ]
        }
    }
    Is this what you were asking about?

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,125
    Answers
    3504
    Vote Rating
    855
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Here is a testcase I tested on 4.0.7 and 4.1.1 RC1 that loads the values for a CheckboxGroup:

    Code:
    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:

    Code:
    {
        "success": true,
        "data": {
            "cb": [
                "1",
                "3",
                "4"
            ]
        }
    }
    Is this what you were asking about?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    56
    Vote Rating
    1
    Bob Wilson is on a distinguished road

      0  

    Default Got it !!!

    Got it !!!


    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.

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,125
    Answers
    3504
    Vote Rating
    855
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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 ===
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread