How set property value of textfield using sightly? | Community
Skip to main content
Adobe Employee
August 9, 2021
Solved

How set property value of textfield using sightly?

  • August 9, 2021
  • 2 replies
  • 2390 views

How set property value of textfield using sightly? or how to add the page title as property value in text field?

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

HI @keerthana_h_n 

 

You want to add/show the default value when the value is not authored in dialog for a field?

You can use below approach:

 

${properties.pageTitle || properties.jcr:title}

So if the pageTitle is not authored it will pick the jcr:title as the default value.

 

Thanks! 

2 replies

Asutosh_Jena_
Community Advisor
Asutosh_Jena_Community AdvisorAccepted solution
Community Advisor
August 9, 2021

HI @keerthana_h_n 

 

You want to add/show the default value when the value is not authored in dialog for a field?

You can use below approach:

 

${properties.pageTitle || properties.jcr:title}

So if the pageTitle is not authored it will pick the jcr:title as the default value.

 

Thanks! 

Asutosh_Jena_
Community Advisor
Community Advisor
August 9, 2021

Hi @keerthana_h_n 

 

Please create a component specific clientlib which will be loaded only during component authoring and load the below JS file.

(function ($, $document) {
"use strict";

$document.on("dialog-ready", function() {
var title = $(document).attr('title');
var titleFromDialog = $(".my-custom-component").find('input[type=text]').val();
if(titleFromDialog == null || titleFromDialog == ""){
$(".my-custom-component").find('input[type=text]').val(title);
}
});

})($, $(document));

on component cq:dialog node add the property called extraClientlibs and provide the category name of your clientlibs which holds the above code.

Provid a custom class to your dialog field where you want to populate the title i.e. my-custom-component here.

 

Now when the dialog value is empty, it will show the page title, and if the value is authored in dialog it will show the dialog authored value.

Let me know if there are any questions. Hope this helps!

Thanks!

Adobe Employee
August 10, 2021

Hi @asutosh_jena_ 

 

To populate description in text field we do samething? bcz I tried to populate description similar way showing undefined.

Asutosh_Jena_
Community Advisor
Community Advisor
August 10, 2021

Hi @keerthana_h_n 

 

You can read the description from metatag using the below command:

$('meta[name=description]').attr('content');

Now this value can be assigned the the respective field using the required selector (ensure correct name or id attribute is used to update the respective field).

 

Thanks!