From eae03349b07019beb389541fa07f5766fe4cfee0 Mon Sep 17 00:00:00 2001 From: Maurice Williams Date: Sat, 12 Dec 2015 23:42:01 -0500 Subject: [PATCH] fixes #81, fixes #104 adding new `attrForSelected` attribute to specify an attribute whose value to use as this elements `value` --- demo/index.html | 15 +++++++++ paper-dropdown-menu.html | 18 ++++++----- test/paper-dropdown-menu.html | 58 +++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 8 deletions(-) diff --git a/demo/index.html b/demo/index.html index 6bb23be..fee90cb 100644 --- a/demo/index.html +++ b/demo/index.html @@ -90,6 +90,21 @@

Pre-selected Value

+
+
+

Custom value attribute

+
+ + + + + +
+
+
+

Disabled

diff --git a/paper-dropdown-menu.html b/paper-dropdown-menu.html index 3701aec..a14c58f 100644 --- a/paper-dropdown-menu.html +++ b/paper-dropdown-menu.html @@ -223,8 +223,9 @@ /** * The value for this element that will be used when submitting in - * a form. It is read only, and will always have the same value - * as `selectedItemLabel`. + * a form. It is read only, and will default to the same value + * as `selectedItemLabel` but can be customized with `attrForSelected` + * attribute on the contained list item. */ value: { type: String, @@ -390,15 +391,16 @@ * optional `label` property. */ _selectedItemChanged: function(selectedItem) { - var value = ''; - if (!selectedItem) { - value = ''; - } else { - value = selectedItem.label || selectedItem.textContent.trim(); + var value = '', + label = ''; + + if (selectedItem) { + label = selectedItem.label || selectedItem.textContent.trim(); + value = selectedItem[this.contentElement.attrForSelected] || label; } this._setValue(value); - this._setSelectedItemLabel(value); + this._setSelectedItemLabel(label); }, /** diff --git a/test/paper-dropdown-menu.html b/test/paper-dropdown-menu.html index a1630b6..8e19910 100644 --- a/test/paper-dropdown-menu.html +++ b/test/paper-dropdown-menu.html @@ -49,6 +49,28 @@ + + + + + + + +