Default Value of Dropdown , not working when inplaceediting

Avatar

Avatar

Veena_Vikram

MVP

Avatar

Veena_Vikram

MVP

Veena_Vikram
MVP

10-11-2020

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 ✌

aem6.5 dropdown inplaceediting

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Veena_Vikram

MVP

Avatar

Veena_Vikram

MVP

Veena_Vikram
MVP

11-11-2020

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.

Answers (4)

Answers (4)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831
Arun_Patidar
MVP

12-11-2020

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

Avatar

Avatar

Anudeep_Garnepudi

Avatar

Anudeep_Garnepudi

Anudeep_Garnepudi

11-11-2020

Hi @Veena_Vikram 

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

Avatar

Anudeep_Garnepudi

Avatar

Anudeep_Garnepudi

Anudeep_Garnepudi

11-11-2020

Hi @Veena_Vikram 

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

Avatar

KiranVedantam1992

Avatar

KiranVedantam1992

KiranVedantam1992

11-11-2020

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)