RED.library without RED.editor?

I've been hacking away at RED.library, trying to understand how it works. I'm actually getting somewhere and managed to save and read information from the library in my test node.

However, I have a question. Is there a way to use the library function and NOT use an editor?

RED.library.create({
                url:"templates", // where to get the data from
                type:"template", // the type of object the library is for
                editor:that.editor, // the field name the main text body goes to
                fields:['name'],
                ext: "txt"
            });

I've tried to not including the editor parameter, which fails, and tried to just create an editor object and not use it, which works but looks kinda ugly:

RED.library.create({
                url:"templates", // where to get the data from
                type:"template", // the type of object the library is for
                editor:RED.editor.createEditor()
});

Any way to just skip it?

Thanks.

Not sure there is a way to skip it. The only uses of the library API for saving individual nodes has been for nodes that have an editor - such as the Function and Template nodes. So it is probably a built-in assumption that there is a editor to save/restore from.

I'm sure it's something that could be improved if there was a specific requirement.

Good to know, thanks knolleary.

I want to use it to save a definition of a Thing in node-red-contrib-hal2, to use as a template for creating other similar Things so you don't have to start from scratch each time. I'll try it, see how far I get! :wink:

Okay, this actually worked pretty well, but I did run into a few problems.

RED.editor obviously, but I got around that by creating an editor object and just not use it.

The node where I want to use RED.library is actually a config node, and RED.library didn't like that much. I ended up creating a hidden input with id='node-input-name' and kept it up to date with an on change function in 'oneditprepare'. Kinda ugly, but works.

  $('#node-config-input-name').on('change', function() {
      $("#node-input-name").val($('#node-config-input-name').val());
  });

Named fields doesn't work for the same reason, but that was fairly easy to get around.

fields:[
      {
          name: 'show_state',
          get: function() {
              return $("#node-config-input-nodestatus").val();
          },
          set: function(v) {
              $("#node-config-input-nodestatus").val(v)
          }
      }
]

It's a great function. I wouldn't mind seeing it getting a bit more love in future releases!

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