Expand my Community achievements bar.

Issue while retrieving multifield data having only one value in JavaScript use api

Avatar

Level 2

Hi,

I am working on a component which uses multifield to get dynamic input from authors. I have one component and javascript file using javascript use api. Author can add items dynamically and remove them. But problem occurs when there is only one value. 

I tried to debug the js code and I identified that

  1. If there are multiple values in multifield then in the log it shows that as "[Ljava.lang.String;".
  2. But if there is only one value then in the log it shows that "{property:value}".

Looks like when only one value is stored in a node then it is stored as one format, but whereas if there are multiple values then its seems to be saved in different format.

Can anyone tell me how to fix this ?

Thank you.

8 Replies

Avatar

Level 10

I am not sure there is anything to fix - i have placed a single item in a MF control (meaning only 1 MF is filled out) and it works fine-  as shown here: 

This single value is written to the web page and it is stored in the dialog. 

Are you seeing either of these conditions when using a single value:

1 - the value is not written to the web page. 

2 - the value is not persisted in the dialog - that is - it disappears when you close and re-open the dialog?

Avatar

Level 2

Hi,

I am using JavaScript Use API. And in that I am facing this issue. I have another java component with similar functionality and it works properly.

Thank you.

Avatar

Level 10

I would use Java that extends WCMUSePojo. When comparing using compiled code in an OSGi vs interrupted JS - i would always recommend using Java. 

Avatar

Level 2

Thank you. I am also using Java that extends WCMUSePojo for all components. But for UI deveopers, JavaScript would be a better option. So trying to use JavaScript UI code. Is it a bug ? Or data storage & data retrieval or different type conversion problem ?

Thank you.

Avatar

Employee

Can you make a small reproducible case/code, and share this?

Avatar

Employee

Can you try to convert the value in JS-code, like what I am doing here to convert string->number

"use strict";
use(function () {
    var count = properties["columCount"];

    return new Array(Number(count));

});