CreativeIT / getmdl-select

Select for material-design-lite
http://creativeit.github.io/getmdl-select/
MIT License
301 stars 87 forks source link

Value of option when it different from caption #55

Closed ar-post closed 7 years ago

ar-post commented 7 years ago

Use data-value attribute to keep real input value not only caption Also value string is fixed by trimming it

ar-post commented 7 years ago

Usage

<li class="mdl-menu__item" data-value="G">Germany</li>
<li class="mdl-menu__item" data-value="B">Belarus</li>

and then

$( '#sample1' ).value;  // Germany
$( '#sample1' ).getAttribute( 'data-value' );  // G
ar-post commented 7 years ago

Trimming should provide for cases like this

<li class="mdl-menu__item" data-value="G">
   <strong>Germany</strong>
</li>
JeckPikachan commented 7 years ago

Actually this already works, but you should use 'data-val', not 'data-value', attribute. Thank you for your request.