Results 1 to 6 of 6

Thread: Get value of radio group

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    49
    Vote Rating
    2
      0  

    Default Unanswered: Get value of radio group

    I have got below panel as an item in another panel.

    My issue is how to get the 'checked' radio button from this radio group(face). Any help will be highly appreciated. Cheers


    Code:
    var faceRating = new Ext.Panel({ 
      height:50,
      width:160,
      //bodyPadding:'0 0 0 20',
      //bodyMargin:'0 0 0 10',
      layout:{
       type:'hbox',
       pack:'justify',
      },
      items:[
             
        {
       
       
       
       xtype:'radiofield',
       
       name:'face',
       
       width:40,
       cls:'radio_rating',
       height:40,
       margin:'0 7 0 7',
       
       
      },
      {
       
       xtype:'radiofield',
       
       name:'face',
        width:40,
        cls:'radio_rating',
        height:40,
        margin:'0 7 0 7',
      },
      {
       
       xtype:'radiofield',
       
       name:'face',
       width:40,
       cls:'radio_rating',
       height:40,
       margin:'0 7 0 7',
      },
      {
       
       xtype:'radiofield',
       
       name:'face',
       width:40,
       cls:'radio_rating',
       height:40,
       margin:'0 7 0 7',
      },
      ],
      
    
    
     });

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,323
    Answers
    3884
    Vote Rating
    1294
      0  

    Default

    Try this:

    Code:
    var faceRating = new Ext.form.FormPanel({
        fullscreen : true,
        height:50,
        width:160,
        layout:{
            type:'hbox',
            pack:'justify'
        },
        items:[
    
            {
    
    
    
                xtype:'radiofield',
    
                name:'face',
    
                width:40,
                cls:'radio_rating',
                height:40,
                margin:'0 7 0 7',
                value : 'one'
    
    
            },
            {
    
                xtype:'radiofield',
    
                name:'face',
                width:40,
                cls:'radio_rating',
                height:40,
                margin:'0 7 0 7',
                value : 'two'
            },
            {
    
                xtype:'radiofield',
    
                name:'face',
                width:40,
                cls:'radio_rating',
                height:40,
                margin:'0 7 0 7',
                value : 'three'
            },
            {
    
                xtype:'radiofield',
    
                name:'face',
                width:40,
                cls:'radio_rating',
                height:40,
                margin:'0 7 0 7',
                value : 'four'
            }
        ],
        dockedItems : [
            {
                xtype : 'toolbar',
                dock  : 'top',
                items : [
                    {
                        text    : 'Get Value',
                        handler : function() {
                            var field = faceRating.query('radiofield');
    
                            console.log(field[0].getGroupValue());
                        }
                    }
                ]
            }
        ]
    
    
    
    });
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    49
    Vote Rating
    2
      0  

    Default

    Can I do this without extending FormPanel but Panel?

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,323
    Answers
    3884
    Vote Rating
    1294
      0  

    Default

    The getGroupValue requires the form.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  5. #5
    Sencha User
    Join Date
    Feb 2012
    Posts
    49
    Vote Rating
    2
      0  

    Default

    By getting clue from your sample code , I used following code still using Panel . I know it may NOT best in performance factor but did work .



    Code:
    handler: function(){
         
         
         var faceRatingValueArray= faceRating.query('radiofield');
         var faceRatingValue="";
         
         for(var i=0;i<faceRatingValueArray.length;i++){
          
          if(faceRatingValueArray[i].isChecked())
            faceRatingValue=legsRatingValueArray[i].getValue();
           
          
         }

  6. #6
    Sencha User
    Join Date
    Sep 2012
    Posts
    4
    Vote Rating
    1
      0  

    Default Use getSubmitValue()

    I ran into the same problem and then checked the source code for Radio class and it turns out that getValue() method returns either 'true' or 'null'.

    Since getGroupValue() calls getValue() in it's return statement it will only return 'true' or 'null'.

    This is obviously a bug.

    The workaround is to use getSubmitValue() instead.

Posting Permissions

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