Reputation: 2648
I have a selection box in my component's dialog, with four options:
In the dialog, I want dynamically set the defaultValue
property to 'off' or 'default' based on whether the URL path contains a certain characters or not. Is this possible?
Here is the dialog.xml snippet with my attempted listener to do this:
<extra_meta_description_tag_mode
jcr:primaryType="cq:Widget"
defaultValue=""
fieldLabel="SEO Description Usage"
name="./extraMetaDescriptionTagMode"
type="select"
xtype="selection">
<listeners
jcr:primaryType="nt:unstructured"
defaultValue="function(url) {
url.contain("en_gb/news") ? return "default" : return "off";
}"/>
<options jcr:primaryType="cq:WidgetCollection">
<off
jcr:primaryType="nt:unstructured"
text="Off"
value="off"/>
<default
jcr:primaryType="nt:unstructured"
text="Append pre-set text"
value="default"/>
<addon
jcr:primaryType="nt:unstructured"
text="Append input text"
value="addon"/>
<over_write
jcr:primaryType="nt:unstructured"
text="Overwrite"
value="overwrite"/>
</options>
</extra_meta_description_tag_mode>
Upvotes: 2
Views: 5068
Reputation: 37
You could also give your component a itemId property with the value: "extra_meta_description_tag_mode", then write an ExtJS plugin and register it for xtype: "selection" and in the init method of your plugin, set the defaultValue property depending on the current page path.
Upvotes: 0
Reputation: 3402
The listener can only have values of events, defaultValue is not one. You can use the loadContent event,which is fired when the dialog loads. CQ.WCM.getPagePath()
will give the current page path:
<listeners
jcr:primaryType="nt:unstructured"
loadcontent="function(selection,record,path) {
var currentPath = CQ.WCM.getPagePath();
if(currentPath.indexOf('en_gb/news')!=-1)
{
selection.setValue('default');
} else {
selection.setValue('off');
}"/>
This will reset the value every time the dialog loads, so you will have add conditions to prevent it if the users have overridden the default value.
Upvotes: 4