Can I pre-populate the values or default in my dialog based on the template. | Community
Skip to main content
adithyaa4585051
Level 2
February 13, 2020
Solved

Can I pre-populate the values or default in my dialog based on the template.

  • February 13, 2020
  • 3 replies
  • 4708 views

Hello All,

 

I have a scenario where I need to change the default values in a dialog based on a template type.

 

Example: 

If I drop my component onto Template 1, the default values of 2 fields in the dialog be 30,40 and when I drag and drop the same component on to a different template then the values in the dialog needs to be changed to 30,40

 

Template 1:

Template 2:

Thanks,

Adithya.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Level 2
February 13, 2020

@adithyaa4585051, It would be better to do the checks from backend and provide overrides in the dialogs for the authors. 

 

But if would like to maintain it only at dialog level, we might have to manipulate few things in the dialog listeners.

Create a dialog listener, get the current page json and retrieve the resourceType or template name and you can add the required values in the fields based on the template/resourcetype comparison.

 

Sample Markup:

$(document).on("dialog-ready", function() { //Hard coded the path var url = "http://localhost:4502/content/aem-flash/en/jcr:content.json"; var templateName = ""; $.getJSON(url, function(json) { templateName = json['cq:template']; console.log('templateName is {}', templateName); // Check the template / resource type and update the values in dialog }); });

 

But, if you do this way, this might override the second time if the author updates the value earlier, so you may have to set a condition to update them only when the values are not present(Ideally the first time we dragged and dropped the component)

 

I would suggest, to do the checks from the backend and provide overrides for author instead of the above approach.

Nirmal_Jose
Adobe Employee
Adobe Employee
February 13, 2020

You can create a granite:rendercondition where you can check for the template type and set the default value. 

 

Search rendercondition in crx/de search to see some OOTB samples. eg. /libs/cq/gui/components/renderconditions