Set intial date for node input with type date

#1

Hi folks,
I try to create my own node which contains a input object with the type of date where this input object has as initial value the date of today (like if you use new Date()).

I've already tried something like the following defaults config, but the date input still has his initial value of yyyy-mm-dd.

...
  category: 'function',
        color: '#a6bbcf',
        defaults: {
            name: {value:""},
            date: {value: new Date()}
        },
        inputs:1,
        outputs:1,
...
0 Likes

#2

Your new Date() call there will be evaluated whenever the editor is loaded - so the value will reflect that and not the point in time the node is added (which is what I assume you want?)

Also, you cannot use Date type for properties as it cannot be JSON encoded - you need to chose how to store the value as either a string or number.

You would then need to use the oneditprepare and oneditsave functions to populate the field from the node value and vice versa.

1 Like