[paper-dropdown-menu] The return value for 'selectedItemLabel' and 'value' is inconsistent, always getting the 'undefined' value result for my form submit

196 views
Skip to first unread message

hsi...@gmail.com

unread,
Dec 18, 2016, 11:19:07 PM12/18/16
to Polymer
Hi,

I am using the 'paper-dropdown-menu' and return the selected menu item value back to server by calling req.body.category.

<paper-dropdown-menu name="category" label="Category" required>
  <paper-menu attr-for-selected="value" class="dropdown-content">
     <paper-item value="Entertainment">Entertainment</paper-item>
     <paper-item value="News">News</paper-item>
     <paper-item value="Technology">Technology</paper-item>       
     <paper-item value="Others">Others</paper-item>
  </paper-menu>
</paper-dropdown-menu>

However, I am facing the below problem which the "selectedItemLabel'" does return the correct selected value of <paper-item>, but getting the "value" always return 'undefined' result.

var s = document.querySelector('paper-dropdown-menu');
     console.log(s.selectedItemLabel); --> OUTPUT 'News' if I select News
     console.log(s.value);  --> OUTPUT 'undefined'

Further reading the 'value' property from polymer document, it does mentioned that 'label' is a read only String type and "will always have the same value as "selectedItemLabel", which is not TRUE for my case as proven above. Is this a bug or something I did wrong inside my code. Thanks.

Statement for "value" from Polymer paper-dropdown-menu document:
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.

Roger

hsi...@gmail.com

unread,
Dec 22, 2016, 2:14:14 AM12/22/16
to Polymer, hsi...@gmail.com
Hi,

For anyone who is interested. After looking further into the Polymer code, it turns out to be a simple solution by modifying the 'paper-dropdown-menu.html' and add ' name="[[name]]" ' inside paper-input template to make it work. Otherwise, calling the req.body.name will never work I assume this is bug which should be fixed by Polymer team - just in my own opinion.

Roger

hsi...@gmail.com於 2016年12月19日星期一 UTC+8下午12時19分07秒寫道:
Reply all
Reply to author
Forward
0 new messages