Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Default Value of Dropdown , not working when inplaceediting

Avatar

Community Advisor

Hi All

 

    I have a component which has two tabs 

 

Tab 1 - RTE

Tab 2 - A dropdown with some values, let's say 1,2,3,4,5

 

  For me 5 is the default value which the author should see when he opens the dialog. So I have set selected=true on this value

 

Now I have inplaceediting enabled for the RTE. I have two issues which I need to solve

 

  1. When the author edits the dialog only via inplaceediting , the dropdown value is not set.
  2. After inplace editing , when I open the dialog using wrench icon , I see the dropdown value is 1 and not 5 ( which is not my default value but the first value in the order of values are added).

Am I missing something here ? Any help is appreciated 

 

edit :- the issue I am trying to tackle here is when author edits component via pencil (inplaceediting), basically he changes the text field alone, but when he open the dialog next time via wrench icon, he see that the dropdown is set to 1 instead of 5 (which as per him should not have changed unless he changed it ) . I understand that the defaultValue won't work when the component is authored already , but what I am trying to get a solution here is to either set the dropdown property to the backend when the user edits the component via pencil, so that when he opens the dialog next time , he see the default value

 

TIA 

Veena ✌

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

6.5
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

I think I figured out a solution. The issue what we are facing in this case was little weird than usual , as the business expectation was that way

 

  When the dialog has two tabs , and the user authors the dialog via inplace editing, only the RTE values are set in the node. Which means the node is already set , but the second tab values are not set. So when the user opens the dialog (via wrench icon) next time, he will not see the default value on dropdown as it will work only for the first time when the dialog is not authored. 

 

The possible solution I was looking at was to set this dropdown property ( lets call it as "dropdownval" ) at the same time the author edits the dialog via pencil icon ( In Place editing) . So what I did is I wrote a server side JS and wrote the below script in it 

 

use(function(){

 

 if(properties.get("dropdownval") == null){

      currentNode.setProperty("dropdownval","5");

      currentNode.getSession().save();
}

 

})

 

This will set the property "dropdownval" to the node, as soon the first time it is authored ( via InPlace or dialog)

 

PS: THIS IS JUST A HACK I FIGURED OUT.

View solution in original post

13 Replies

Avatar

Community Advisor

The selected property will not work if the value is already authored. Can you please check if you have authored it already? Also please let us know the resourceType you are using (Coral or Granite)

Avatar

Community Advisor
Yeah , the issue I am trying to tackle here is exactly same, author edits it via pencil, so basically he changes the text field alone, but when he open the dialog next time via wrench icon, he see that the dropdown is set to 1 instead of 5 (which as per him should not have changed unless he changed it ) . I understand that the defaultValue won't work when the component is auhtored already , but what I am trying to get a solution here is to either set the dropdown property to the backend when the user edits it via pencil, so that when he opens the dialog next time , he see the default value

Avatar

Community Advisor

Hi @VeenaVikraman 

1) Inplace editing is only for the the particular field(RTE), on submit only one particular field value will  submitted. As the complete dialog form is not submitted you don't see other values.

2) Setting property seleted(boolean) true to option(not for first, I did set for n-1 option)  , is working perfectly for me with both coral2 and coral3 select widgets.

AG

Avatar

Community Advisor
@Anudeep_Garnepudi , thanks for quick response , I understand Point 1 , Point 2 is the problem, it works fine for authoring via wrench icon, but not if you are authoring the component only via Inplace editing.

Avatar

Community Advisor
Apologies , it is in my client code and can't copy, that is why I gave a complete dialog detail in the question

Avatar

Correct answer by
Community Advisor

I think I figured out a solution. The issue what we are facing in this case was little weird than usual , as the business expectation was that way

 

  When the dialog has two tabs , and the user authors the dialog via inplace editing, only the RTE values are set in the node. Which means the node is already set , but the second tab values are not set. So when the user opens the dialog (via wrench icon) next time, he will not see the default value on dropdown as it will work only for the first time when the dialog is not authored. 

 

The possible solution I was looking at was to set this dropdown property ( lets call it as "dropdownval" ) at the same time the author edits the dialog via pencil icon ( In Place editing) . So what I did is I wrote a server side JS and wrote the below script in it 

 

use(function(){

 

 if(properties.get("dropdownval") == null){

      currentNode.setProperty("dropdownval","5");

      currentNode.getSession().save();
}

 

})

 

This will set the property "dropdownval" to the node, as soon the first time it is authored ( via InPlace or dialog)

 

PS: THIS IS JUST A HACK I FIGURED OUT.

Avatar

Administrator
Thank you for sharing this with the Community.


Kautuk Sahni

Avatar

Community Advisor

Hi @VeenaVikraman 

I would suggest don't set properties from support script or from any view script. Because it is presentation layer and suggested not to write any update/create logic with in a view. A simple solution for your use case is

use(function(){
properties.get("dropdownval", "5");
});

ValueMap has overloaded get method which will take default value as parameter. If the property is null. It will return the value that we provided. 

AG

Avatar

Community Advisor

properties.get  will return you the value if it is set , but the issue here is the value itself is not present in the node. I want to set that value, so that next time when the author opens the dialog , he will see that default values in the dropdowns properly. I know might be my use case is little confusing, but if you follow the steps I mentioned in the question, you will understand the issue correctly. And I don't think doing a little hack via server side JS won't be that bad

Avatar

Community Advisor

you can simply set the default value for dropdown item using value property or using cq:template.

Please note, this will reflect the changes only for new edits existing authored component will not have any impact



Arun Patidar

Avatar

Community Advisor
Thanks @arunpatidar . Unfortunately , this bug was raised for existing pages