diff options
author | Adam Chlipala <adam@chlipala.net> | 2018-10-12 10:57:26 -0400 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2018-10-12 10:57:26 -0400 |
commit | 5eaaa94db962bbc3e42578bce3463ff2f942d602 (patch) | |
tree | 20e0882b48b32df611505d2a6829240cfb7ccf74 /lib | |
parent | fe05947bf2f4b6f5090c80f85424ebd09a320444 (diff) |
Catch when a cselect has an unavailable value set
Diffstat (limited to 'lib')
-rw-r--r-- | lib/js/urweb.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js index ff4c7b7e..199f5001 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -1230,11 +1230,14 @@ function selectValue(x) { function setSelectValue(x, v) { for (var i = 0; i < x.options.length; ++i) { - if(x.options[i].value == v) { + if (x.options[i].value == v) { x.selectedIndex = i; return; } } + + if (v != "") + er("Setting <select> to nonexistent value: " + v); } function sel(s, content) { @@ -1243,8 +1246,8 @@ function sel(s, content) { var dummy = document.createElement("span"); dummy.innerHTML = "<select>" + content + "</select>"; - var x = input(dummy.firstChild, s, function(x) { return function(v) { if (selectValue(x) != v) setSelectValue(x, v); }; }); + var x = dummy.firstChild; for (var i = 0; i < x.options.length; ++i) { if (x.options[i].value == "") x.options[i].value = x.options[i].text; @@ -1252,6 +1255,8 @@ function sel(s, content) { x.options[i].value = x.options[i].value.substring(1); } + x = input(x, s, function(x) { return function(v) { if (selectValue(x) != v) setSelectValue(x, v); }; }); + setSelectValue(x, s.data); if (selectValue(x) != s.data) sv(s, selectValue(x)); |