Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: custom json objects in CustomValue or (better) customfield in fields definition #68

Open
szacchino opened this issue Feb 12, 2019 · 0 comments

Comments

@szacchino
Copy link

szacchino commented Feb 12, 2019

Hi,
great work here! I tried to customize templates to allow generation of an HTML Select input for one of my fields. Currently I added a bunch of fields in the customValue field of base.json. Currently they are:

"fieldXY": 3,
"fieldXYvalue1": "1",
"fieldXYlabel1" : "Option 1",
"fieldXYvalue2": "2",
"fieldXYlabel2" : "Option 2",
"fieldXYvalue3": "3",
"fieldXYlabel3" : "Option 3"

that I parse in the template as

<#if (field.type?string == "com.liferay.damascus.cli.json.fields.Integer" && application.customValue[field.name]?? ) >
  <aui:select name="${field.name}" disabled="false" label='<%=LanguageUtil.get(request, "${lowercaseModel}-${field.name?lower_case}") + requiredLabel%>'>
    <aui:option value="" label="Select a value"/>
    <#list 1..application.customValue[field.name]?number as optionIdx>
      <#assign optionvalue = application.customValue[field.name+"value"+optionIdx?string] />
      <#assign optionlabel = application.customValue[field.name+"label"+optionIdx?string] />
      <aui:option value="${optionvalue}" label="${optionlabel}"/>
    </#list>
  </aui:select>
</#if>

I saw that customValue is implemented as a Map<String, String> so it is a sort of key-value map. Maybe a Map<String, Object> could be better for having custom objects in base.json that can be used in templates.
So in base.json it could be:

"customValue" : {
       "fieldXY": {
            "items": [
                {value:1, label: "Option 1"},
                {value:2, label: "Option 2"},
                {value:3, label: "Option 3"}
          ]
         }
      }

Even better could be having a custom object in the field definition so that one can specify custom code based on field data.
So for an integer field in base.json it could be:

{
  "type": "com.liferay.damascus.cli.json.fields.Integer",
  "name": "fieldXY",
  "title": "Field Title",
  "required": "true" {
  "items": [
     {value:1, label: "Option 1"},
     {value:2, label: "Option 2"},
     {value:3, label: "Option 3"}
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants