Skip to content

Improve and further Test DSI_unit input widget

this issue is referencing to the dsi_unit input and its test in branch https://gitlab1.ptb.de/digitaldynamicmeasurement/dcc-and-dsi/dsiunits-js/-/tree/feature/unitInput

The input widget should not accept invalide units or at least mark them in red.

\ampere\tothe{2}\volt\tothe{3}\per\metre\per\metres

unit.warnings already contains information about the incorrectness of the unit.

see end of visual test file

https://gitlab1.ptb.de/digitaldynamicmeasurement/dcc-and-dsi/dsiunits-js/-/blob/feature/unitInput/tests/visual_test.html?ref_type=heads#L267-L280

const renderBtn = document.getElementById('renderBtn');
    renderBtn.addEventListener('click', () => {
        const inputStr = document.getElementById('dsiInput').value;
        try {
            const unit = new DSIUnit(inputStr);
            const renderedHTML = unit.toHTML();
            let warningsHTML = "";
            if (unit.warnings.length > 0) {
                warningsHTML = `<div id="warningText">Warnings: ${unit.warnings.join("; ")}</div>`;
            }
            document.getElementById('interactiveResult').innerHTML = renderedHTML + warningsHTML;
        } catch (err) {
            document.getElementById('interactiveResult').innerHTML = `<span style="color:red;">Error: ${err.message}</span>`;
        }