8

I have a programmatically generated dijit.form.Select. Unlike most other widgets, the Selects do not offer a resize method like

dijit.resize({w: width, h: height});

I have not found a standardized way of setting the width of a select. This is quite bad because the autosizing makes Dialogs "explode" on long select values.

Is there a standard way to resize a select I have missed? Or do I have mess with the markup of the select the hard way?

Thanks!

5 Answers 5

9

This can be achieved with CSS by setting the width of the inner label like this:

.tundra .dijitSelect .dijitButtonText {
    text-align: left;
}

.tundra .dijitSelectLabel {
    width: 120px;
    overflow: hidden;
}
1
  • 1
    What if I want to set the width to 100%? or what if I want to set width as wide as its parent element? width: 100%; did not work, any idea how to set it in this case?
    – Mai
    Commented Aug 18, 2015 at 10:24
3

Why wouldn't you simply do this by setting the widget's style?

http://jsfiddle.net/QEjYD/1/

Unfortunately, due to how the widget is written, this doesn't work if you hook up the width in a CSS class, or if you set the width style after the widget has been created.

3
  • Thank you! That was actually the problem: I needed to resize the select AFTER the widget has been created. Was not aware of the fact that it works before creation.
    – Steffen
    Commented Oct 4, 2010 at 7:38
  • @ken This creates a fixed width though right? Im struggling with setting a 'max' width. If a user selects 'option 2' I want the select to be 150px if they select 'sdfsdfsdfds fdsfdsdfdasf asfasdfadsf adsfasf' The select should truncate up to a max of 450px. I've done this using css but IE8 has a max-width and overflow hidden bug - so for ie8 I have some js that resizes it the issue with the js solution is the select 'flashes' to a different position before the js can resize it. If a short value is selected then a long one there is a flash of the select being in the wrong position. Ugly Fix.
    – maehue
    Commented Oct 18, 2012 at 1:05
  • 2
    @MigoFast: Ken's answer doesn't really work once you start trying to add options. (See jsfiddle.net/QEjYD/568) James's answer below does, however. See jsfiddle.net/QEjYD/569 Commented Nov 26, 2012 at 16:09
3

Give style to constructor:

var mySelect = new Select({
      id: 'mystatus',
      name: 'mystatus',
      style: {width: '150px'},
      required : false, 
      store: os,
      searchAttr: 'label',
  }, "mystatus");
1

I would use

dojo.marginBox(selectWidget.domNode, {w: width, h:height})
1
  • Thanks for the answer! Tried that already, but that screws up the select dijit (the dropdown arrow on the right fills out the additional width, the real select value stays autosized as before). Guess I'll have to modify it the hard way, thanks anyway!
    – Steffen
    Commented Sep 25, 2010 at 9:21
0

try this

.dijitSelect .dijitButtonNode {
  width: 16px !important;
}

dom-style.set(dojo.query('.dijitSelect')[0], 'width', with);

Not the answer you're looking for? Browse other questions tagged or ask your own question.