Added JavaScript to restore selected options (easier than making it work

in Mustache).
This commit is contained in:
Markus Birth 2016-05-26 00:28:35 +02:00
parent f2decbf6a1
commit c807857e27
5 changed files with 22 additions and 4 deletions

18
js/frs.js Normal file
View File

@ -0,0 +1,18 @@
document.addEventListener("DOMContentLoaded", function(event) {
var all_selects = document.getElementsByTagName('select');
for (var i in all_selects) {
if (!all_selects.hasOwnProperty(i)) {
continue;
}
var xsel = all_selects[i];
var xvalue = xsel.dataset.value;
//console.log('Value of %o = %o', xsel, xvalue);
// Walk all options, compare to desired value and set if matches
for (var o in xsel.options) {
if (xsel.options[o].value == xvalue) {
xsel.selectedIndex = o;
break;
}
}
}
});

View File

@ -29,7 +29,7 @@
</button>
</form>
<script src="./js/frs.js" charset="utf-8"></script>
{{> mdl_content_foot}}
{{> mdl_foot}}
{{> html_foot}}

View File

@ -1,6 +1,6 @@
<div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label">
<!-- https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 -->
<select id="{{field_id}}" name="{{field_id}}" {{#required}}required{{/required}} size="1" class="mdlext-selectfield__select">
<select id="{{field_id}}" name="{{field_id}}" {{#required}}required{{/required}} size="1" class="mdlext-selectfield__select" data-value="{{value}}">
<option value=""></option>
<option value="DE">Germany</option>
<option value="UK">United Kingdom</option>

View File

@ -1,6 +1,6 @@
<div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label">
<!-- https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 -->
<select id="{{field_id}}" name="{{field_id}}" {{#required}}required{{/required}} size="1" class="mdlext-selectfield__select">
<select id="{{field_id}}" name="{{field_id}}" {{#required}}required{{/required}} size="1" class="mdlext-selectfield__select" data-value="{{value}}">
<option value=""></option>
<option value="EUR">Euro - €</option>
<option value="USD">US Dollar - $</option>

View File

@ -1,6 +1,6 @@
<div class="mdlext-selectfield mdlext-js-selectfield mdlext-selectfield--floating-label">
<!-- https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 -->
<select id="{{field_id}}" name="{{field_id}}" {{#required}}required{{/required}} size="1" class="mdlext-selectfield__select">
<select id="{{field_id}}" name="{{field_id}}" {{#required}}required{{/required}} size="1" class="mdlext-selectfield__select" data-value="{{value}}">
<option value=""></option>
<option value="http://schema.org/Confirmed">Confirmed</option>
<option value="http://schema.org/Cancelled">Cancelled</option>