Closed sttng closed 5 years ago
Do you mean a default values in Control?
You can call setValue or define a default value in node.data[key]
, where key
is a second parameter in the contructor
setValue doesn't work yet, because Vue render isn't ready yet. So basically "...vueContext.value" doesn't exists yet. Key is not the Value of the Control, but rather the "name" of the Control. I checked the CodePen https://codepen.io/Ni55aN/pen/xzgQYq and I cant set a default value for lets say a number Control ("NumControl) of Number Component either. For ex. maybe I would like the default to be "100" for every Number Component added - while of course the users can still set it to whatever he / she likes.
mounted() {
this.value = this.getData(this.ikey);
}
here you can set an initial value, for example:
let val = this.getData(this.ikey);
this.value = val === undefined ? 100 : val;
OK I choose a different approach, which lets me call the Control Constructur and define the default value dynamically
1) Add default (defaultVal) value to Constructor and to props property:
class NumControl extends Rete.Control {
constructor(emitter, key, readonly, defaultVal) {
super(key);
this.component = VueNumControl;
this.props = { emitter, ikey: key, readonly, defaultVal};
}
var VueNumControl = {
props: ['readonly', 'defaultVal', 'emitter', 'ikey', 'getData', 'putData'],
mounted() {
this.value = this.getData(this.ikey);
let val = this.getData(this.ikey);
this.value = val === undefined ? this.defaultVal : val;
this.update();
}
I am working (in my free time) on a RenderMan node editor using rete.js (https://github.com/sttng/slim-shady). I want to prepopulate some values (some of them are to be user editable later, some aren't). How would I prepopulate control values during constructor calling ?