PDA

View Full Version : Set a segmented Button to pressed



coolate
14 Sep 2011, 9:27 PM
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!

mitchellsimoens
15 Sep 2011, 5:03 AM
segmentButton.setPressed(1);

coolate
15 Sep 2011, 6:58 AM
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:

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


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..

mitchellsimoens
15 Sep 2011, 7:00 AM
You have to do it on the actual segmented button instance... you are trying to do it on an Array.

coolate
15 Sep 2011, 7:32 AM
I feel really stupid, not sure what you mean. I use the buttons like this:

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!!

mitchellsimoens
15 Sep 2011, 7:36 AM
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.

coolate
15 Sep 2011, 11:53 AM
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:

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:

var segButton = rootPanel.getDockedComponent(0).down('segmentedButton');


segButton.setPressed(true);

Although, I am not sure how it would set the second button...
and


segmentedButton.getComponent(2).setPressed(true);
or

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!

mitchellsimoens
15 Sep 2011, 11:56 AM
segmentedButton.setPressed(1);

This will make the button at index 1 pressed.

coolate
15 Sep 2011, 12:01 PM
Ohhhhh works! This is what I did to get it going then for me...

segmentedButton.setPressed(1, true);


THANK YOU!!!

=NR=
25 Feb 2014, 6:15 PM
according to this:

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

(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...