-
6 Dec 2012 2:38 AM #1
Answered: SelectField popup styling
Answered: SelectField popup styling
Hi,
I have a select field that opens a pop up with selectable choices if I click on it. My question is, how do I get to style this pop up (with css)? (I need to adjust it's size).
The problem is that I can't set the id on it, and although I set an id on the select field, the pop up itself is not child of the field in the dom but its on a much higher level (so I can't write a css rule that selects that kind of element inside the given select field).
If I style the popup instead regardless of which field it belongs to, it will be styled for all instances of course, which I don't want to do..
-
Best Answer Posted by mitchellsimoens
There are two different things you can style. For a phone it uses a picker that comes from the bottom where you can configure with the defaultPhonePickerConfig config on the select field. For the floating panel with a child list you can use defaultTabletPickerConfig config.
-
6 Dec 2012 3:18 AM #2
I had the same problem, my items didn't fit because the width of the popup was too small.
What you can do is set the property: usePicker: true which opens a picker instead of popup.
-
8 Dec 2012 5:49 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
- Answers
- 3107
There are two different things you can style. For a phone it uses a picker that comes from the bottom where you can configure with the defaultPhonePickerConfig config on the select field. For the floating panel with a child list you can use defaultTabletPickerConfig config.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
1 Feb 2013 9:04 AM #4
Mitchell I'm not sure exactly what to do with the popupStyling. Basically I'd like to adjust the height of the popup based on the number of items to display. Usually I only have 2-3 items in there (it is dynamic), but currently the popup sizes to about 10 items. usePicker:true doesn't look great on a tablet. Any suggestions?
Thanks
-
1 Feb 2013 9:20 AM #5
It's been a while since I dealt with this, but I think I solved it with this config on the selectfield:
Either this, or getting the needed object through a chain of getters on the select fieldCode:"defaultTabletPickerConfig": [ "{id: \"myPicker\"} // so we can change the size (width) in css" ]
-
1 Feb 2013 9:28 AM #6
Ahkay, yea that seems like a reasonable solution. I just modified the sencha code to simply adjust the height ( within reason) based on the number of items in the store. It's not perfect but I'm curious why not have something similar in there the first place, rather than a big ol' popup with lots of unnecessary whitespace.
Code:showPicker: function() { var store = this.getStore(); //check if the store is empty, if it is, return if (!store || store.getCount() === 0) { return; } if (this.getReadOnly()) { return; } this.isFocused = true; if (this.getUsePicker()) { var picker = this.getPhonePicker(), name = this.getName(), value = {}; value[name] = this.getValue(); picker.setValue(value); if (!picker.getParent()) { Ext.Viewport.add(picker); } picker.show(); } else { var listPanel = this.getTabletPicker(), list = listPanel.down('list'), index, record; store = list.getStore(); //added the following. var height = list.getStore().getCount() * 53; if( height > 318 ){ height = 318; } listPanel.setHeight( height + 'px' ); // end changes. ideally the 53 number would be automagically obtained from the list item cmp. index = store.find(this.getValueField(), this.getValue(), null, null, null, true); record = store.getAt((index == -1) ? 0 : index); if (!listPanel.getParent()) { Ext.Viewport.add(listPanel); } listPanel.showBy(this.getComponent()); list.select(record, null, true); } },
-
2 Mar 2013 9:32 AM #7
I modified your override to use the lists itemHeight in the calculation rather than the hardcoded 53. This appeared to be slightly off as the height of the last item in the list seemed to be smaller than the rest. Adding an offset of 3 seems to have made it better. In short I changed
toCode:var height = list.getStore().getCount() * 53;
Code:var height = list.getStore().getCount() * (list.getItemHeight() + 3);
-
2 Mar 2013 9:46 AM #8
Nice, maybe we will see that in ST 2.1.2

BTW to patch this for builds, the file is sdk/src/field/Select.js


Reply With Quote