Select widget not showing null selection item

Hi,
I’m noticing this behavior for the Select widget. If I use the default Select, I don’t see the null selection item id that I specify, but if I switch the select to be the NativeSelect, I can see it for the same code… Is this by design? If yes, could you tell how to show the null selection item value I specify for the Select component?

— code —


Select opts = new Select("Select caption");
//        AbstractSelect opts = new NativeSelect("Select caption");    //The null selection item shows up for this!
        opts.addItem("Test 1");
        opts.addItem("Test 2");
        String nullItem = "-- Select one --";
        opts.setNullSelectionItemId(nullItem);

        opts.setValue(nullItem);

        opts.setImmediate(true);

        opts.addListener(new Property.ValueChangeListener() {
            public void valueChange(Property.ValueChangeEvent event) {
                getMainWindow().showNotification("Selected item: " + event.getProperty());
            }
        });

btw, is there a way to attach screenshots to forum messages without uploading it elsewhere and directly embedding in the post via an attachment?

Hello,

seems that you don’t add the nullItem to your Select. So, you should add the following line to your code:

opts.addItem(nullItem);

Unfortunately adding any attachments isn’t currently allowed for users without administration privileges. I’ll see what I can do about it.

Thanks, Teemu. That works! I don’t know how i missed that. I guess since it worked with the native select without adding the null item, I assumed I was doing it right… Anyway, thanks again! :slight_smile: