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 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,553
    Answers
    3931
    Vote Rating
    1272
      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! Checkout the CODE tag!

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

  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,553
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    The getGroupValue requires the form.
    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

  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
  •