Native Select Empy Value

hi,

I’ve found a possible bug and we need a fix for that.
here’s it it…

in Native Select there is a Empty value contained in the Option list always

<select tabindex="0" class="v-select-select" size="1" style="width: 100%; ">
<option></option>
<option value="1">400</option>
</select>

java code for this is…


 NativeSelect select = new NativeSelect()
 select.addItem("400")

is it possible to remove that?

thanks

Did you try setNullSelectionAllowed(false)?

If there is no selection when the component is shown initially, an empty item is added regardless of the setting but removed when something is selected.

i am posting my question here because i am not able to post a new thread
when i click on post (in new thread) it shows there is some problem with our data base :frowning:

my question is

hi all
i have started working with vaadin a few days ago so i do not have much knowledge about it.
i am facing problem with native select value change event.

what i am doing is adding a native select to a layout and adding a value change listener to it. but the listner is getting called even for the first time load. here is my code :



private NativeSelect testnative;    //declaring native select
 testnative = new NativeSelect();
        testnative.setNullSelectionAllowed(false);   //setting null alowed false
        buttonsAbsoluteLayout.addComponent(testnative, "top:4.0px;left:324.0px;");   // adding component to layout 
        testnative.setImmediate(true);
        testnative.addItem(test.One);   //adding items
        testnative.addItem(test.Two);
        testnative.addItem(test.Three);
        testnative.setItemCaption("One");   //setting captions
        testnative.setItemCaption("Two");
        testnative.setItemCaption("three");
        testnative.addListener(new Property.ValueChangeListener() {    //adding listner
   			
			@Override
			public void valueChange(ValueChangeEvent event) {    // overriding valueChange method 
				// TODO Auto-generated method stub
				String value=event.getProperty().toString();
				//System.out.println("\n\n\n\n\n\n value :"+value);
				getWindow().showNotification("Selected : " + event.getProperty());
				
				
			}
		});


when the window containing above layout is rendered a notification is displayed “Selected :One”.
i want that notification should come only when the value of native select is changed.

please help!!!

Are you sure you don’t have any other code than that? What Vaadin version are you using?

How can user enter values through keyboard in NativeSelect ?
In my project the requirement only through NativeSelect. Can we customize the behaviour of NativeSelect for ???
Please help me…Urgent.

NativeSelect isn’t designed for user inputing value like in a Textfield. Why not use a Combobox?

How can user enter values through keyboard in NativeSelect ?
In my project the requirement only through NativeSelect. Can we customize the behaviour of NativeSelect for ???
Please help me…Urgent.

Problem being that the NativeSelect is based on a Html Select tag with option tags below it so you’re pretty much limited to that. You could possible make the actual NativeSelect so small that only the arrow is shown and then add a TextField before it.

The combobox on the other hand consists out of a text input field and a button which opens a PopUpView-kind-of-thing.
I honestly don’t get the requirement just being limited to NativeSelect because you can style a Combobox to look like a NativeSelect.

Hi Henri Sara,

i have done the same way but still i am having issue.

NativeSelect mySlt=new NativeSelect();
mySlt.setNullSelectionAllowed(false);

I am using vaadin 7.1.10 , i think it is 4 years thread sorry for posting here.

Advance thanks .

hi Sara ,

My observation is , when you set correct selected value then blank item will not come , blank value will come when you dont select an item.

Hi there,

I’m creating a language selector with NativeSelect. To achieve this, I use icons everywhere in the select.
I already added captionIcon to the select, it is half a success.

I tried to programmatically fill the items which turned out half success only.
FlagImage class code is under the following section

try{
            flagImages = new FlagImage();
        }catch(Exception e){
            
        }
        
        Map<String, Resource> imageResources = flagImages.getImages();
        
        Iterator it;
        it = imageResources.entrySet().iterator();
        Object item;
        
        languageSelector.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ICON_ONLY);
        while(it.hasNext()){
            Map.Entry pair = (Map.Entry)it.next();
            item = languageSelector.addItem();
            languageSelector.setItemIcon(item, (Resource)pair.getValue());
            languageSelector.setItemCaption(item, (String)pair.getKey());
            it.remove();
        }

FlagImage:

[code]
public class FlagImage {

private final Map<String, Resource> imageResources = new HashMap<>();
private static final String FLAG_IMGS_LOCATION = "/static/flags/";
private final Iterator<Language> it = Arrays.asList(Language.values()).iterator();

public FlagImage() throws URISyntaxException {
    while (it.hasNext()) {
        final String lang = it.next().toString().toLowerCase();
        final File imgFile = new File(this.getClass().getResource(FLAG_IMGS_LOCATION.concat(lang).concat(".png")).toURI());
        final Resource resource = new FileResource(imgFile);
        imageResources.put(lang, resource);
    }
}

public Map<String, Resource> getImages() {
    return imageResources;
}

}
[/code]Language.values() are returned enum values, there are 3 of them.
So the map is filled on FlagImage and the map is being extracted on the other class.
First I forgot to change setItemCaptionMode to ICON_ONLY and the keys were showing up properly in the select’s dropdown menu. After changing to ICON_ONLY, the select’s dropdown has 3 empty lines.

What is the issue? Why the flags aren’t turning up?

Hi,

I ended here because I’m experiencing this too. How is that that an empty item is added even if I have set NullSelectionAllowed to false until one element is selected??