v3.23.5 review: the numeric result display and the single datalist
Two findings from the review of e0dfc10:
- trResultFormValue stringified the stored value, so a numeric result
(an API-authored or hand-imported script - the engine reads ints as the
value) was misread as hex: 10 showed as '10 - cancel' (0x10) instead of
the value 0x0A, 16 matched no option and fell back to '00 - ok', and
saving the step wrote the shown option back, silently changing the value.
Numbers are converted to their hex form first.
- trResultRowHtml rendered the 'tr-addinfo-list' datalist on every call, so
the drain's form (respond + first) carried two elements with the same id.
It is rendered once per form (an opts.list flag on the first result row;
the second row and the source pin the single occurrence).
Tests: the numeric form values, the datalist only with {list: true} and the
two-row composition rendering exactly one. 855 frontend + 838 Python.
This commit is contained in:
+16
-5
@@ -8045,6 +8045,11 @@ function trResultOptions() {
|
||||
// A stored result -> the select's value and the manual hex ('' unless the
|
||||
// value is not in the list). Accepts the aliases, the hex and the 0x form.
|
||||
function trResultFormValue(stored) {
|
||||
// a numeric stored value (an API-authored script: the engine reads ints as
|
||||
// the value, not as hex) -> its hex form
|
||||
if (typeof stored === 'number') {
|
||||
return trResultFormValue(stored.toString(16).toUpperCase().padStart(2, '0'));
|
||||
}
|
||||
const raw = String(stored === undefined || stored === null ? '' : stored).trim();
|
||||
if (raw === '') return {value: '', manual: ''};
|
||||
if (TR_RESULT_ALIASES[raw.toLowerCase()]) return {value: raw.toLowerCase(), manual: ''};
|
||||
@@ -8094,9 +8099,13 @@ function trResultRowHtml(selId, stored, addInfo, opts) {
|
||||
html += '<div class="mt-1 flex gap-2 items-center"><label class="text-xs text-gray-500 dark:text-slate-400 shrink-0">'
|
||||
+ esc(t('Additional information (optional hex byte)')) + '</label>'
|
||||
+ '<div class="w-24">' + testFormInput(selId + '-addinfo', add, '00', 'list="tr-addinfo-list" maxlength="2"') + '</div></div>';
|
||||
html += '<datalist id="tr-addinfo-list">'
|
||||
+ TR_RESULT_ADD_INFO.map(a => '<option value="' + esc(a.v) + '">' + esc(a.name) + '</option>').join('')
|
||||
+ '</datalist>';
|
||||
// the suggestion list once per form (opts.list) - a form may carry several
|
||||
// result rows (the drain's respond + first) and duplicate ids are invalid
|
||||
if (opts && opts.list) {
|
||||
html += '<datalist id="tr-addinfo-list">'
|
||||
+ TR_RESULT_ADD_INFO.map(a => '<option value="' + esc(a.v) + '">' + esc(a.name) + '</option>').join('')
|
||||
+ '</datalist>';
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -8213,7 +8222,8 @@ function testStepRender() {
|
||||
} else if (step.kind === 'proactive-drain') {
|
||||
const pr = p.respond || {};
|
||||
html += testFormRow('TERMINAL RESPONSE result (each command)',
|
||||
trResultRowHtml('test-f-presult', pr.result === undefined ? 'ok' : pr.result, pr.additional_info));
|
||||
trResultRowHtml('test-f-presult', pr.result === undefined ? 'ok' : pr.result, pr.additional_info,
|
||||
{list: true}));
|
||||
const pf = p.first || {};
|
||||
html += testFormRow('First command only (optional)',
|
||||
trResultRowHtml('test-f-pfirst', pf.result === undefined ? '' : pf.result, pf.additional_info,
|
||||
@@ -8261,7 +8271,8 @@ function testStepRender() {
|
||||
+ '<div id="test-checks"></div></div>';
|
||||
const r = step.respond || {};
|
||||
html += testFormRow('TERMINAL RESPONSE result',
|
||||
trResultRowHtml('test-f-result', r.result === undefined ? 'ok' : r.result, r.additional_info));
|
||||
trResultRowHtml('test-f-result', r.result === undefined ? 'ok' : r.result, r.additional_info,
|
||||
{list: true}));
|
||||
html += testFormRow('Item identifier (SELECT ITEM / SET UP MENU)', testFormInput('test-f-ritem', r.item_id, '1..255'));
|
||||
html += testFormRow('Text (GET INKEY / GET INPUT)', '<div class="flex gap-2">'
|
||||
+ testFormInput('test-f-rtext', r.text, 'text')
|
||||
|
||||
Reference in New Issue
Block a user