Expand my Community achievements bar.

SOLVED

designdialog and dialog date format issue

Avatar

Level 1

Hi team,

 

in design dialog i have created 3 different date formats when i am calling in dialog using "displayed format" property like changing value dynamically. i'm getting unknow language error in dialog.

 

dialog screenshot:

naveenp1258706_0-1693135034505.png

 

 

design dialog screenshot:

it is dropdown 

naveenp1258706_1-1693135087771.png

 

naveenp1258706_2-1693135140911.png

 

on page it is displaying unknown language.

 

naveenp1258706_3-1693135196006.png

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
By researching further of granite coral datepicker, found that value uses Expression Language using getExpressionHelper, hence value transform into design dialog value. 

 

String value = cmp.getValue().val(
  cmp.getExpressionHelper().getString(cfg.get("value", "")));​​​​​

On the other hand, dateFormat is evaluated as static string. 

attrs.add("displayformat", 
  i18n.getVar(cfg.get("displayedFormat", String.class)));

 

It appears that this behavior is expected. The reason you're encountering random values is due to certain characters coinciding with date format placeholders like 'D', 'e', and 'a'. As a result, these characters are being substituted with the corresponding values.

Reference:
/libs/granite/ui/components/coral/foundation/form/datepicker/init.jsp
/libs/granite/ui/components/coral/foundation/form/datepicker/render.jsp

View solution in original post

2 Replies

Avatar

Community Advisor

The ${cqDesign.propertyName} variable works with the 'value' and 'granite:hide' properties in the component dialog. In case of other properties, act as static strings without executing expressions. 
https://myaemlearnings.blogspot.com/2018/04/cqdesign-variable-in-expression.html 

HTML code generates "displayFormat=${cqDesign.dateFormat}" as indicated in the screenshot below.

Screenshot 2023-08-27 at 10.12.41 PM.png 

 

As an alternative, I believe you can use standard date format on Component Dialog. Later, you can show the date in the HTML based on the chosen selection in the design dialog using Sling Model.

@ScriptVariable
protected Style currentStyle;

if(this.currentStyle != null) {
  String displayFormat = currentStyle.get("displayFormat", DEFAULT_FORMAT);
  //format your date here
}

 

 

Avatar

Correct answer by
Community Advisor
By researching further of granite coral datepicker, found that value uses Expression Language using getExpressionHelper, hence value transform into design dialog value. 

 

String value = cmp.getValue().val(
  cmp.getExpressionHelper().getString(cfg.get("value", "")));​​​​​

On the other hand, dateFormat is evaluated as static string. 

attrs.add("displayformat", 
  i18n.getVar(cfg.get("displayedFormat", String.class)));

 

It appears that this behavior is expected. The reason you're encountering random values is due to certain characters coinciding with date format placeholders like 'D', 'e', and 'a'. As a result, these characters are being substituted with the corresponding values.

Reference:
/libs/granite/ui/components/coral/foundation/form/datepicker/init.jsp
/libs/granite/ui/components/coral/foundation/form/datepicker/render.jsp