jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.61k stars 721 forks source link

Multi level value update #171

Closed SamuraiDante closed 3 years ago

SamuraiDante commented 3 years ago

Was having an issue and it appears that when updating the value of a input and having it mapped using the multi level attribute, such as df-level1-level2-value, it would insert {level1-level2-propertyname: value} into the data instead of {level1:{level2:{propertyname: value}}}.

I changed updateNodeValue to this:

    updateNodeValue(event) {
        var attr = event.target.attributes
        for (var i = 0; i < attr.length; i++) {
            if (attr[i].nodeName.startsWith('df-')) {
                var keys = attr[i].nodeName.slice(3).split("-");
                var target = this.drawflow.drawflow[this.module].data[event.target.closest(".drawflow_content_node").parentElement.id.slice(5)].data; 
                for (var index = 0; index < keys.length - 1; index += 1) {
                    if (target[keys[index]] == null) {
                        target[keys[index]] = {};
                    }
                    target = target[keys[index]];
                }
                target[keys[keys.length - 1]] = event.target.value;
            }

        }
    }

This seemingly fixed the issue.

Just thought I'd give you a heads up.

jerosoler commented 3 years ago

Thanks! Again @SamuraiDante 👏

Fix in 0.0.42!