how to get id of a node in TinyMCE? - tinymce

I want to get the id of a node inside TinyMCE.
I searched in the documentation, but could not find this.
How can this be done?

First, it is important which node you want to get the id from.
If you want to get the if of the parent node of your selection in TinyMCE use
tinymce.activeEditor.selection.getNode().id;
EDIT: In case you have a single node in your editor you can access this node id using
tinymce.activeEditor.getBody().firstChild.id;

let say if you have id as txtatinyID
<textarea class="editorHtml" id="txtatinyID"></textarea>
so following will return txtatinyID in tinyMCE V4
$(tinymce.activeEditor.selection.getNode()).closest('body').data('id')
So it will find the body of the current active editor and on the base of it will look for body and in it will get the value of data-id.

Related

Integrate ${Category.displayName} in Demandware content slot

There is way to show ${Category.displayName} in regular Demandware Content Slot? Please let me know if there are other options how I can show actual category name inside a content asset.
Thanks in advance for your help.
Assuming this is a Category type content slot configuration you can access the categories you configured via ${slotcontent.content} which is an iterator of categories (you can use only the first element in your use case and ignore if there is more than one category).

AEM DefaultValue written to JCR

I noticed that when I set my defaultValue for a dropdown, altho it is correctly selected in the drop down when I first add my component to the page it does not write the defaultValue to the corresponding JCR until I edit the component and save it. Even if I just open the corresponding dialog and click OK now my component works as expected because the values have been added to the JCR.
I am sure there is an important piece that I am missing here, does anyone knows how defaultValues that are required in order for the component to render properly can be added to the JCR when they are first added to the page?
Like Shwan say's that's the way it works. The default values or empty texts are only for the dialog. They aren't persisted until the dialog is authored. The properties have to be set by a different method. CQ already ships with this feature and you can do it without any custom code.
Under your component , create a node called cq:template[nt:unstructured] . If all the data is stored on the component node itself , add the default values as properties to cq:template node with name same as the ones in your dialog. In case the data is stored in a child node add a similar node under cq:template node.
Source : http://blogs.adobe.com/experiencedelivers/experience-management/defaults-in-your-component/
I believe that is simply the way it works. The default value specified in a dialog does not get used until the dialog is loaded/saved, so until that happens the node on the JCR repository that is being authored won't have the default value.
We got around this on a project by adding back-end code that was tied to the component (a tag) so that when the component was loaded, if the property did not exist, it would be written with the default the first time. Ex:
if (wcmMode == WCMMode.EDIT )
{
if(!currentNode.hasProperty("SomePropertyThatWillAlwaysExistIfTheDialogHasBeenSaved")) {
currentNode.setProperty("PropertyThatShouldHaveDefault", GlobalConstants.TRUE);
currentNode.getSession().save();
}
}
Like Sharath Madappa say's that's the way it works fine if component name and jsp name same. If you dont have componentname.jsp under component or page, cq:template won't work.(Reference:http://labs.6dglobal.com/blog/2014-07-08/using-the-cq-template/)
If you hava componentname.html under your component, changed the node [cq:template] type to [cq:Template] instead of [nt:unstructured]. In this case, defaultValues can be added to the JCR when they are first added to the page.

Find CURRENTLY selected <option> with XPath

What's the correct XPath syntax to check if an option element is currently selected, or just to get the selected option element from a select element, on an open page with which the user, and JavaScript, may have interacted? Is this even possible with XPath, or does it lack the ability to look at DOM properties?
I can't find any documentation on this, and have (speculatively) tried:
//option[#selected=true]
//option[#selected="selected"]
//option[#selected]
but none of these work; they simply don't match any elements.
(In case it matters, I've tried this both using the $x function in the Chrome developer console, and using the find_elements_by_xpath method in Selenium for Python.)
Short answer: it's not possible.
Longer answer: XPath can look at HTML attributes, but it can't look at DOM properties. Selecting an <option> element in a <select> changes the selected property of the <option> to true, and also changes the value property of its parent <select> element, but it doesn't affect the attributes of either, so it is invisible to XPath.
To find <option> elements that have the selected attribute set, which is often how a page author might determine which option is initially selected, you can use //option[#selected]. But this does not find the currently selected <option>; changes that the user makes to the selection are invisible to XPath. There's no guarantee it will even find the initially selected option, since it's possible that the page author didn't put the selected attribute on any elements and either let the browser select the first option by default or had some JavaScript select the initial option via the selected property.
The multiple other answers here claiming that a selector like //option[#selected] can detect selection changes made by the user after the page loads are simply completely wrong.
Of course, if you're able to use CSS selectors instead of XPath selectors, then option:checked will do the job.
The problem could be the " (double quotes).
//select/option[#selected='selected'] - Will match the selected option, i am using this successfully.
//select/option[#selected='selected' and #value='specific value'] - Will only match the selected option if it has a 'specific value', i'm also using this.
If you are still having trouble, it could be an entirely different problem, perhaps there is no option node. I hope this helps.
I think we can use a knowledge from #Mark's answer and account that. Let's just find a node which HAS desired attribute:
tree.xpath('//select/option[#selected]/text()')[0].strip()
I tried "//option[#selected=''] and it has worked for me.
it is able to highlight the selected option within Page objects model.
I would try //option[#selected='true']
i.e. driver.findElements(By.xpath("//option[#selected='true']")).getText();

In CQ How disable the topmost node of a tag

Is there any way to disable the topmost node of a tag when I am adding a tag.
It is like suppose I have a dialog in which there is a field with xtype= tags and the tag is XYZ under which A, B, C are child nodes.
I want the author to select only A or B or C. He can not select XYZ.
How can I implement this. in the tagging_field.js
Thanks.
Sorry for replying after long time, this might be helpful for others. This can be achieved something like this, if the user/author selects xyz tag the value gets added to the tag field, you can get the array of values added in the tag field using getValue method and if the array contains the xyz value delete the value and setValue back to the tag field using setValue method
Here is the link to API docs for tag field for you to refer. Tag Field API Docs
Regards,
Yash Ahuja.

Access select using div/span id

In jquery is it possible to access a select element by simply using the div or span id plus the "select" selector? I ask because i have a series of auto-generated forms meaning I can't assign an id to the form elements plus the names are weird like "w24", I'd like to access a form element specifically a select using the surrounding span id and "select" selector example:
$("#hiv_care select").attr("disabled",true);
I've tried this but it doesn't work, forcing me to explicitly use the dropdown name.
Seems I was using the wrong div id. SLaks thanks for the link to jsfiddle.net it exposed my ways and is really helping me with testing out my jquery code.