thanhlong203 / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

goog.ui.ComboBox return item Caption rather than item Value when define ComboItems with model #308

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?

1. Create a goog.ui.ComboBox with Items
2. Each item has model
3. When you selected one comboItem, e.target.getValue return Caption rather 
than Item Value.

<CODE EXAMPLE>
        var cb = new goog.ui.ComboBox();
        cb.setUseDropdownArrow(true);
    cb.setFieldName("comboIdiomas");
    cb.setDefaultText('Select lang');
    cb.addItem(new goog.ui.MenuItem('Español','ES'));
    cb.addItem(new goog.ui.MenuItem('English','EN'));
    cb.render(goog.dom.getElement("mensaje"));

    goog.events.listen(cb, goog.ui.Component.EventType.CHANGE, function(e) {
        alert("Value: " + e.target.getValue());
    });
</CODE EXAMPLE>

What is the expected output? What do you see instead?
Expected ES or EN (Item Value). I see Español or English (Item Caption)

What version of the product are you using? On what operating system?
latest closure verion on Windows 7 with Google Chrome 10.0.648.204 and FireFox 
3.6.16

Please provide any additional information below.

You can see one demo on 
http://commondatastorage.googleapis.com/sdebug/index.html

I see the problem was located on goog/ui/combobox.js on 
goog.ui.ComboBox.prototype.onMenuSelected_

var caption = item.getCaption();
this.labelInput_.setValue(caption);

item.getValue() isn't returned to combobox.

Thanks for all.

Original issue reported on code.google.com by moisesbe...@gmail.com on 5 Apr 2011 at 9:15

GoogleCodeExporter commented 8 years ago
ComboBox allows the user to enter any custom texts. It doesn't necessarily have 
to have an associated model.

If you need the model of the selected item, you can listen to the 
goog.ui.Component.EventType.ACTION event.

Original comment by pall...@google.com on 5 Apr 2011 at 9:25