Results 1 to 4 of 4

Thread: Checkbox group BULK LOAD

  1. #1
    Sencha User
    Join Date
    Sep 2010
    Posts
    56
    Vote Rating
    1
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    56
    Vote Rating
    1
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •