Setting initial dropdown value for dynamic dropdown?

I'm creating a custom node that reads a list of effect values values dynamically from a remote server and populates a dropdown for its edit page. I've got the dropdown populating just fine, and the resulting selected effect makes its way to my code at node execution time just fine as well.

Where I'm struggling is setting the value of the dropdown when the edit page opens to the last value selected by the user. The only reference I can find to how to do this is an old message from 2017 on StackOverflow. Unfortunately when I simply try and use this.effect in code it's always undefined. Debugging a bit shows that this is always the overall window object, not my node object.

Any tips on what I'm missing here? I'm sure it's something obvious. The complete edit page HTML is on github. Thanks!

You need to use jquery to set the dropdown to the value saved in your config. For example look at the code of one of my nodes where it is this line:

Agreed. My problem is with this in your example, which doesn't seem to work for me:

When I do that and dump it via console.log() it's the entire Window object. Attempting to directly access the value with node.effect returns undefined.

The problem is you have defined your oneditprepare as an arrow function:
You cannot do that here - it needs to be a regular function so that this is define.


Arrrrggggggh. I knew it was something simple. Thank you, works like a charm now!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.