# Input type checkbox

**URL:** <https://discourse.nodered.org/t/input-type-checkbox/43511>\
**Category:** Developing Nodes\
**Created:** [1 April 2021 12:10 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511 "2021-04-01T12:10:53Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [12 April 2021 09:09 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/21 "2021-04-12T09:09:39Z")

</div>

yes i tried some things in oneditsave and i cant make it work.I read it multiple times but cant manage it to work  
EDIT: I now did this just to see if my previous code works fine and it does. This logs The text of every option added to the list

```auto
oneditsave: function() {
  let list = $(".list")[0];
      for (let i = 0; i < list.children.length; i++) {
        console.log(list.children[i].innerText);
      }
}

```

---

<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:** [12 April 2021 09:16 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/22 "2021-04-12T09:16:56Z")

</div>

I'm sorry, looking at your code, you have ignored all of the advice I posted.

I cannot help you any more.

---

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [12 April 2021 09:19 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/23 "2021-04-12T09:19:24Z")

</div>

Thanks anyways.

---

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [12 April 2021 10:04 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/24 "2021-04-12T10:04:00Z")

</div>

```auto
 let inputNo = 1;
            const addToList = () => {
              let selectedItems = $("#node-input-options option:selected");
              selectedItems.each(function (i, el) {
                let inputId = "node-input-dynamic-options" + inputNo;
                // console.log(el, i);
                let text = $(el).text();
                let val = $(el).val();
                var li = $("<li>").text(text).val(val).attr({
                  value: val,
                  id: inputId,
                  class: "mynode-dynamic-element",
                });
                console.log(li[0]);
                list.append(li);
                li.on("dblclick", function () {
                  li.remove();
                  inputNo--;
                });
                btnClear.on("click", function () {
                  li.remove();
                  inputNo = 1;
                });
                inputNo++;
              });
            };
            btn.on("click", addToList);
          });
      };
      fetchUrl();
    },
    oneditsave: function () {
      let dynElements = $(".mynode-dynamic-element");
      let dynOpts = [];

      this.dynamicOptions = dynOpts;
    },

```

Tried like this for now. Am i on good track?

---

<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:** [12 April 2021 10:18 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/25 "2021-04-12T10:18:01Z")

</div>

> [@jake123](#):
>
> Am i on good track?

Yes. apart from i dont thing `btnClear.on` should probably not be in the loop. Worry about that later.

In fact the code I wrote for `oneditsave` is exactly what you want.

Just make sure you have added `dynamicOptions` to the `defaults` as i explained in earlier post.

NOTE: once you have this working & saving your dynamic options - there is still a job to do - you need to (in oneditprepare) read the value of `dynamicOptions` and re-populate the list.

* * *

Try the `oneditsave` code I wrote in the "solution" i provided.

test your node, add some dynamic items, click done, deploy.

then put a debugger in `oneditprepare` (at the top) - you should see your dynamic options from before - use these to re-build the list.

---

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [12 April 2021 12:02 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/26 "2021-04-12T12:02:30Z")

</div>

I know this isnt still right but i've made some proggress.

```auto
 oneditprepare: function () {
      let list = $(".list");
      let dynamicOptions = this.dynamicOptions;
      for (let i = 0; i < dynamicOptions.length; i++) {
        let listText = dynamicOptions[i].text;
        const myNewListItem = $("<li>").text(listText);
        list.append(myNewListItem);
      }

```

```auto
oneditsave: function () {
      let dynElements = $(".mynode-dynamic-element");
      let dynOpts = [];
      dynElements.each(function (index, el) {
        let textValue = $(el)[0].innerText;
        console.log(textValue);
        let opt = {
          text: textValue,
        };
        dynOpts.push(opt);
      });

```

Can i somehow make the li that populates after oneditsave stay there always unless i delete it?

---

<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:** [12 April 2021 12:44 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/27 "2021-04-12T12:44:05Z")

</div>

> [@jake123](#):
>
> Can i somehow make the li that populates after oneditsave stay there always unless i delete it?

No, thats not how it works.

oneditprepare - is for you to populate user fields UI  
oneditsave - is for you to accept UI user field & store them in the node property

the node properties that get stored (in oneditsave) are available in the oneditprepare for you to re-populate the user fields UI.

---

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [12 April 2021 13:51 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/28 "2021-04-12T13:51:12Z")

</div>

Probably same thing but have to try and ask. The li stays 2nd time i open the node and then if i close it again and open, lis are gone. Could i make them stay until i select some other options no matter how many times i reopen the node

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 April 2021 14:49 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/29 "2021-04-12T14:49:06Z")

</div>

> [@jake123](#):
>
> Could i make them stay

No. When the edit dialog is closed, all of its contents are destroyed. The only way to save information is using `oneditsave` to store information in the node properties. You then use `oneditprepare` to use that information from the node properties to rebuild the edit dialog.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 April 2021 14:49 UTC](https://discourse.nodered.org/t/input-type-checkbox/43511/30 "2021-04-26T14:49:27Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/input-type-checkbox/43511.md?page=1)
