Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asker functions to "know" the current node #24

Open
michmech opened this issue Oct 17, 2017 · 2 comments
Open

Asker functions to "know" the current node #24

michmech opened this issue Oct 17, 2017 · 2 comments

Comments

@michmech
Copy link
Owner

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
Copy link

+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
Copy link

rtosman commented Apr 8, 2019

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;
}		

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants