Results 1 to 10 of 10

Thread: Set a segmented Button to pressed

  1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    South Bend, IN
    Posts
    26

    Default Answered: Set a segmented Button to pressed

    I am sure this is very simple and I am missing it. I am trying to set a segmented button or radio button, in my code, to pressed.
    I have tried a number of thing, like this:
    Ext.getCmp('resultsButton').addCls('{pressed: true;}');
    Am I thinking about this the wrong way?
    Thanks!

  2. Code:
    segmentedButton.setPressed(1);
    This will make the button at index 1 pressed.

  3. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,392
    Answers
    3997

    Default

    Code:
    segmentButton.setPressed(1);
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Sep 2011
    Location
    South Bend, IN
    Posts
    26

    Default

    Thanks for the reply! I am still not getting it to work though, so I must be doing something wrong.
    I tried this by creating a variable for the button like so:
    Code:
    var resultsButton = [ {
    					xtype: 'button',
    	                text: 'Results',
    					id: 'resultsButton',
                        scope: this,
    	                handler: tapResults
    	            }];
    				var buttonsGroup2 = [{
    				            xtype: 'segmentedbutton',
                                
    				            items: [{
    				                text: 'Enter Data',
    								id: 'dataButton',
                                    pressed : true,
    				                handler: tapData
    				            }, resultsButton , {
    				                text: 'Saved',
    								id: 'savedButton',
    				                handler: tapSaved
    				            }]
    				        }];
    Then later I call

    Code:
    resultsButton.setPressed(true);
    When its called I get a "undefined' is not a function (evaluating 'resultsButton.setPressed(true)')" error in the console.

    I am sure I am missing something very obvious here..

  5. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,392
    Answers
    3997

    Default

    You have to do it on the actual segmented button instance... you are trying to do it on an Array.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  6. #5
    Sencha User
    Join Date
    Sep 2011
    Location
    South Bend, IN
    Posts
    26

    Default

    I feel really stupid, not sure what you mean. I use the buttons like this:
    Code:
    var dockedItems = [ {
    					xtype: 'toolbar',
    					ui: 'light',
                        layout:{
                            pack: 'center',
                         
                        },
    					items: buttonsGroup2,
    					dock: 'top'
    					 }];
    Then just have it as the dockedItem in my main Pane.

    Have you seen an example I could look at out there? I have looked at all the examples I could find...

    Thanks for your patience and help!!

  7. #6
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,392
    Answers
    3997

    Default

    Code:
    var segButton = panel.getDockedComponent(0).down('segmentedbutton');
    
    segButton.setPressed(1);
    Something along those lines. What it is doing is getDockedComponent(0) gets the toolbar at index 0 and down('segmentedbutton') gets the first direct child of the toolbar.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  8. #7
    Sencha User
    Join Date
    Sep 2011
    Location
    South Bend, IN
    Posts
    26

    Default

    Thanks again for your reply, but I am still having little luck...


    I get an error "'undefined' is not a function" for the setPressed.

    I looked around a bit, and this is close to what I am trying, but its not working ether.
    http://blog.paranormalcop.org/?p=22

    I changed my segmentedButton too this:
    Code:
    resultsButton = [ {
    					//xtype: 'button',
    	                text: 'Results',
    					pressed : false,
    					id: 'resultsButton',
                        scope: this,
    	                handler: tapResults
    	            }];
    			segmentedButton = new Ext.SegmentedButton ({
    				           // xtype: 'segmentedbutton',
                                id: 'segmentedButton',
    				            items: [{
    				                text: 'Enter Data',
    								id: 'dataButton',
                                    pressed : true,
    				                handler: tapData
    				            }, resultsButton , {
    				                text: 'Saved',
    								id: 'savedButton',
    				                handler: tapSaved
    				            }]
    				        });
    and tried a number of things like:
    Code:
    var segButton = rootPanel.getDockedComponent(0).down('segmentedButton');
    
    
    			segButton.setPressed(true);
    Although, I am not sure how it would set the second button...
    and

    Code:
    segmentedButton.getComponent(2).setPressed(true);
    or
    Code:
    Ext.getCmp('segmentedButton').getComponent(2).setPressed(true);
    and many more... I feel reeealy dumb, I am sure this is simple, and I am messing up....
    Thanks again!

  9. #8
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,392
    Answers
    3997

    Default

    Code:
    segmentedButton.setPressed(1);
    This will make the button at index 1 pressed.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  10. #9
    Sencha User
    Join Date
    Sep 2011
    Location
    South Bend, IN
    Posts
    26

    Default

    Ohhhhh works! This is what I did to get it going then for me...

    segmentedButton.setPressed(1, true);


    THANK YOU!!!

  11. #10
    Sencha User =NR='s Avatar
    Join Date
    Mar 2013
    Location
    Singapore
    Posts
    115
    Answers
    2

    Default Maybe there is bug in the documentation

    according to this:

    http://docs.sencha.com/touch/2.3.1/#!/api/Ext.SegmentedButton-method-setPressedButtons

    the method take an array as parameter instead of number which is suggested and WORKS here...

Posting Permissions

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