modbselect onchange not working

Issue #361 resolved
Zaher Salman created an issue

onchange event is not triggered for modbselect.

Comments (3)

  1. Zaher Salman reporter

    Looking at the code (and if I understand it correctly) it seems that onchange is replaced with data-validate (line 1218). So I have to use data-validate=”function..” instead of onchange=”function..”. But there is still a bug on line 1222, it should be

    let flag = eval(this.dataset.validate);
    

    Also, to get the change propagating to the odb the following lines should come after the eval command

    mjsonrpc_db_set_value(this.dataset.odbPath, this.value);
    mhttpd_refresh();
    

  2. Stefan Ritt

    The code is correct. The validation function gets called with the current value and the DOM element, thus we have

    let flag = eval(this.dataset.validate)(this.value, this);
    

    The validation can return "true" or "false". If returned false, the value does not get propagated to the ODB. So the mjsonrpc_db_set_value call comes after the if (!flag) statement.

  3. Stefan Ritt

    Ok, I realized that any user onchange=”…” gets overwritten by the framework which is not good. So I replaced the framework code with .addEventListener(“change”, …) and now we can have both a user “onchange” function and the framework correctly sending data to the ODB. The change is comitted.

  4. Log in to comment