I have paper-listbox elemnt in a paper-dropdown-menu, values of items are different from labels. Here is the example
<paper-dropdown-menu label="Gender" name="gender" required error-message="Gender is required">
<paper-listbox slot="dropdown-content" attr-or-property-name="value">
<paper-item value="M">Male</paper-item>
<paper-item value="F">Female</paper-item>
</paper-listbox>
</paper-dropdown-menu>
But in the post, the label is given instead of the value of the item
Any idea to have gender=M
or gender=F
in the request?
It is possible, though you have to add an id
attribute to the paper-listbox
and dig a bit:
<dom-module id="item-value-demo">
<template>
<style></style>
<paper-dropdown-menu label="Gender" name="gender" required error-message="Gender is required">
<paper-listbox id="gender" slot="dropdown-content" attr-or-property-name="value">
<paper-item value="M">Male</paper-item>
<paper-item value="F">Female</paper-item>
</paper-listbox>
</paper-dropdown-menu>
</template>
<script>
class ItemValueDemo extends Polymer.Element {
static get is() { return 'item-value-demo'; }
ready() {
super.ready();
this.$.gender.addEventListener('selected-item-changed', e => { this._genderOption(e) });
}
_genderOption(e) {
const value = e.target.selectedItem;
if (value) {
console.log(value.attributes["value"].value);
}
}
}
customElements.define(ItemValueDemo.is, ItemValueDemo);
</script>
</dom-module>
<item-value-demo></item-value-demo>
See this pen.