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
oneditsave: function() {
let list = $(".list")[0];
for (let i = 0; i < list.children.length; i++) {
console.log(list.children[i].innerText);
}
}
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.
I know this isnt still right but i've made some proggress.
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);
}
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?
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
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.