retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.17k stars 653 forks source link

NaN at the Beginning in all Text Controls #331

Closed DasDarki closed 5 years ago

DasDarki commented 5 years ago

Hey, I have an issue with a Vue Text Control. Everytime you come to the beginning of a custom text control and write one letter, the first char is everytime 'NaN'. When you remove the whole value than there is a 0 and than you write again, first char is NaN.

Here the Code:

const VueTextControl = {
        props: ['readonly', 'emitter', 'ikey', 'getData', 'putData'],
        template: '<input type="text" :readonly="readonly" :value="value" @input="change($event)" @dblclick.stop="" @pointermove.stop=""/>',
        data() {
            return {
                value: 0,
            }
        },
        methods: {
            change(e) {
                this.value = +e.target.value;
                this.update();
            },
            update() {
                if (this.ikey)
                    this.putData(this.ikey, this.value)
                this.emitter.trigger('process');
            }
        },
        mounted() {
            this.value = this.getData(this.ikey);
        }
    };

    class TextControl extends Rete.Control {

        constructor(emitter, key, readonly) {
            super(key);
            this.component = VueTextControl;
            this.props = {emitter, ikey: key, readonly};
        }

        setValue(val) {
            this.vueContext.value = val;
        }
    }

Maybe i am stupid, or this is a bug idk. Thanks in advanced and have a nice day

DasDarki commented 5 years ago

EDIT: I found out, when you enter text, the NaN will be at the beginning and when you transform the Editor to a JSON String the corresponding value is null. But when you enter a number, it behaves normal. The value in the JSON isnt null, its the right value and no NaN appeards.

DasDarki commented 5 years ago

Ok nevermind. I am just stupid. I just copied the Vue Num Control and changed just the text at the input. But I had to change the update function to. The '+' had to be removed and now its working super fine :D