# Custom node with values from global

**URL:** <https://discourse.nodered.org/t/custom-node-with-values-from-global/44977>\
**Category:** Developing Nodes\
**Created:** [30 April 2021 09:49 UTC](https://discourse.nodered.org/t/custom-node-with-values-from-global/44977 "2021-04-30T09:49:39Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 May 2021 12:09 UTC](https://discourse.nodered.org/t/custom-node-with-values-from-global/44977/18 "2021-05-04T12:09:16Z")

</div>

> [@jake123](#):
>
> You probably wont understand a word im saying

not really but i guess you want this `#node-input-options` to have the previous selection when the user re-opens the editor?

> [@jake123](#):
>
> EDIT: Its probably because my fetch function calls oneditprepare so it repopulates the dropdown everytime i reopen the node. Is there any way to get around this?

As I have said in other posts, you need to persist the selection in a node.propertyXXX upon `oneditsave` then in the `oneditprepare` function, when you do the fetch & populate the dropdown, use the persisted `node.propertyXXX` value to re-select the item,

See a full explanation [here](https://discourse.nodered.org/t/input-type-checkbox/43511/16)

So for example...

```auto
              data.forEach((item) =>
                  let value = item.name;
                  let text = item.name;
                  options.push({ v: value, t: text, });
                  $("#node-input-options").append(
                    $("<option></option>").attr("value", value).text(text)
                  );
                  if(value == node.selectedValue) $('#node-input-options').attr('selected','selected'); //<<<<<
              );

```

- `node.selectedValue` is something you need to set when the select is changed.
- that means you need to have an `$("#node-input-options").on("change", function(){ ...}`
- and you need to add `selectedValue` to the `defaults` object

---

_[View the full topic](https://discourse.nodered.org/t/custom-node-with-values-from-global/44977)._
