Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How set property value of textfield using sightly?

keerthana_hn
Level 3
Level 3

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

1 Accepted Solution
Asutosh_Jena_
Correct answer by
Community Advisor
Community Advisor

HI @keerthana_hn 

 

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! 

View solution in original post

7 Replies
Asutosh_Jena_
Correct answer by
Community Advisor
Community Advisor

HI @keerthana_hn 

 

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! 

View solution in original post

keerthana_hn
Level 3
Level 3

Hi @Asutosh_Jena_

 

I need to display the page title in my dialog textfield as default. How can that be achieved?

Asutosh_Jena_
Community Advisor
Community Advisor
Is it the page component dialog or any custom component dialog you want to show?
keerthana_hn
Level 3
Level 3
Custom component dialog. Need to populate the page title as textfield value in dialog by default. While authoring can be edited.
Asutosh_Jena_
Community Advisor
Community Advisor

Hi @keerthana_hn 

 

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));

asutosh_jena_0-1628527940037.png

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

asutosh_jena_1-1628528012904.png

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

asutosh_jena_2-1628528073091.png

 

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!

keerthana_hn
Level 3
Level 3

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

Hi @keerthana_hn 

 

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!