michmech / xonomy

A schema-driven XML editor for the web.
MIT License
91 stars 32 forks source link

Asker functions to "know" the current node #24

Open michmech opened 7 years ago

michmech commented 7 years ago

Currently, an asker function cannot "see" the node it is being invoked on. This can be a problem, for example if you are writing a custom asker function, a value picker where the options offered depend on the value of some attribute or some such. So, we need asker functions to be able to access the current node (via a surrogate object).

afriedle commented 6 years ago

+1

I just started using xonomy and already ran into this issue. The documentation says when it comes to custom asker functions:

  1. The third argument is a surrogate object representing the attribute the asker function is being invoked on. For surrogate objects see Chapter 10. From this you can traverse the entire XML document. You can use this to customize the contents of the asker depending on the value of some other attribute, say, or indeed on anything else in the XML document.

That's simply not true, the actual surrogate object you receive looks like this:

Xonomy.surrogate {internalParent: undefined, type: "attribute", name: "type", htmlID: "xonomy11", value: "int"}

This surrogate structure isn't defined in chapter 10 (For example: There is no "internalParent" anywhere in the documentation).

Is the documentation outdated (Based on it there should be a parent function, but it's missing for askers)? Or is this a bug?

rtosman commented 5 years ago

I too, just started using Xonomy and quickly ran into this issue. I need to write a custom picker that has a variant list based on the name of the parent node.

based on the documentation I added the function below. Which does not work, mind you I also can't get the "onchange" or "validate" calls to be invoked, so I might be doing something more fundamental wrong (but based on the comments here, it doesn't appear as if the following code would work).

asker: function(htmlID, param, sur) {
    var html="";
    if(sur.parent().attributes["name"].includes("algorithm")) {
        var picklist = [ "aes128", "aes256"];
        html+=Xonomy.pickerMenu(picklist, "aes128");
    }  else {
        var picklist = [ "ecc", "rsa"];
        html+=Xonomy.pickerMenu(picklist, "ecc");
    }
    return html;
}