Getting Started | API | Elements | Actions | Validators | Handlers | Configuration Options | Advanced Guides | Troubleshooting | About
Nitrogen 2.x allows you to reference element paths using jQuery selectors. These selectors can be used in three contexts:
As the target (first parameter) of wf:wire/2
, wf:update/2
, wf:insert_top/2
, wf:insert_bottom/2
, etc.
As the trigger (first parameter) or target (second parameter) of wf:wire/3
.
As the trigger
or target
of an #event{}
action.
Path matching in Nitrogen is complicated because it must provide a simple, straight-forward interface while still accounting for potential name-collisions due to the nested nature of Nitrogen elements.
For example, you should be able to create two elements with the same ID, but in different areas of the element hierarchy, and be able to reference those elements in predictable ways.
The objs(Path, Anchor)
function is used to match selectors on the client. This is defined in /nitrogen.js/, and returns a jQuery object containing all of the elements that match the selector provided under Path
, potentially in close proximity to the selector provided under Anchor
. If Anchor
is not provided, then the anchor set by Nitrogen.$anchor(Anchor, Target)
is used.
Nitrogen.$anchor/2
is automatically called by Nitrogen before each action is rendered. The Anchor
value is set to the uniquely generated temp ID for the element to which the action applies, it will look something like .wfid_temp23422
.
Unless you are doing some wacky stuff, your application should not need to worry about calling objs()
or Nitrogen.$anchor()
directly, but it helps to know what is happening behind the scenes in case you need to debug.
If you are trying to wire an action or update a command, and the statement seems to affect the wrong elements, it may help to drop down into a Javascript console and run objs(YourPath)
to see what is actually getting matched.
Here are the steps that the objs()
function takes when matching a path.
If the selector has multiple parts separated by commas, then the selector is split, and each part is combined.
If the selector is "page", then a reference to the DOM document is returned.
The string "##" is replaced with ".wfid_". This allows you to specify Nitrogen elementIDs in a string selector. For example "##myelementid > .someclass" will be rewritten to ".wfid_myelementid > .someclass". This is done because Nitrogen uses classes to tag your elements with their ID, so an element with ID of 'myelementid' will be tagged with a class called '.wfid_myelementid'.
If the string "me" is found surrounded by non-word characters, it is replaced with the anchor that was set. This allows you to write paths such as "me > .image" which will apply to all elements with class ".image" under the current element.
If the path is a one word string and it is the name of an HTML element such as "table", "div", "h1", etc., then try matching as a Nitrogen element ID first, and if that doesn't work, then try matching as an HTML element.
If a string is found containing only words separated by periods (for example, "element1.element2"), then it is assumed to be a nested series of elements, and is converted to ".wfid_element1 .wfid_element2". This will match all Nitrogen elements named 'element2' underneath any Nitrogen elements named 'element1'.
If the path begins with "body", then match using a call to jQuery(path)
. This will match any elements in the context of the entire document.
Otherwise, Nitrogen will try to match elements as closely as possible starting at the current anchor. First, try to match the path under the current anchor using jQuery(anchor).find(path)
. If results were found, then stop and return. Otherwise, call jQuery(anchor).parents()
to get a list of parents, and then for each parent, call jQuery(parent).find(path)
. If results were found, then stop and return.
Finally, if no elements were found, then Nitrogen resorts to matching jQuery(path)
.
A keyword to specify the context of the current anchor. In other words, if you wire an event to an element, then 'me' will point to that element.
A shortcut for referring to a Nitrogen element when you specify a string path. Because of the way Nitrogen uses class names to tag elements, this is the same as specifying ".wfid_element".
Selectors and descriptions below are pulled directly from the jQuery Selectors Documentation.
Selects all elements.
Select all elements that are in the progress of an animation at the time the selector is run.
Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-).
Selects elements that have the specified attribute with a value containing the a given substring.
Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.
Selects elements that have the specified attribute with a value ending exactly with a given string.
Selects elements that have the specified attribute with a value exactly equal to a certain value.
Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.
Selects elements that have the specified attribute with a value beginning exactly with a given string.
Selects all button elements and elements of type button.
Selects all elements of type checkbox.
Matches all elements that are checked.
Selects all direct child elements specified by "child" of elements specified by "parent".
Selects all elements with the given class.
Select all elements that contain the specified text.
Selects all elements that are descendants of a given ancestor.
Selects all elements that are disabled.
Selects all elements with the given tag name.
Select all elements that have no children (including text nodes).
Selects all elements that are enabled.
Select the element at index n within the matched set.
Selects even elements, zero-indexed. See also odd.
Selects all elements of type file.
Selects all elements that are the first child of their parent.
Selects the first matched element.
Select all elements at an index greater than index within the matched set.
Selects elements that have the specified attribute, with any value.
Selects elements which contain at least one element that matches the specified selector.
Selects all elements that are headers, like h1, h2, h3 and so on.
Selects all elements that are hidden.
Selects a single element with the given id attribute.
Selects all elements of type image.
Selects all input, textarea, select and button elements.
Selects all elements that are the last child of their parent.
Selects the last matched element.
Select all elements at an index less than index within the matched set.
value][name2
value2]Matches elements that match all of the specified attribute filters.
Selects the combined results of all the specified selectors.
Selects all next elements matching "next" that are immediately preceded by a sibling "prev".
Selects all sibling elements that follow after the "prev" element, have the same parent, and match the filtering "siblings" selector.
Selects all elements that do not match the given selector.
Selects all elements that are the nth-child of their parent.
Selects odd elements, zero-indexed. See also even.
Selects all elements that are the only child of their parent.
Select all elements that are the parent of another element, including text nodes.
Selects all elements of type password.
Selects all elements of type radio.
Selects all elements of type reset.
Selects all elements that are selected.
Selects all elements of type submit.
Selects all elements of type text.
Selects all elements that are visible.