Adding a runtime JavaScript value to a Liferay Dynamic Data List

526 Views Asked by At

I have created a Liferay Dynamic Data List (DDL) allowing visitors to enter their name and surname.

In addition to name;surname I would like the DDL to memorize the value of a particular JavaScript variable that my custom theme defines dynamically.

So the data would look like this:

Name | Surname | MyHiddenField
Bob  | Denard  | red
Fulk | Fitz    | blue

How can I create this hidden DDL column and fill it with the JavaScript value?

1

There are 1 best solutions below

0
On BEST ANSWER

Added a normal text field (with an empty label), and at runtime hide it and fill its value by JavaScript.

The input field has a partly random identifier _169_INSTANCE_2VvOlMsuXSQY_myhiddenfield:

<input
  class="aui-field-input aui-field-input-text"  
  id="_169_INSTANCE_2VvOlMsuXSQY_myhiddenfield"
  name="_169_INSTANCE_2VvOlMsuXSQY_myhiddenfield"
  type="text"
  value="" />

So you have to match the suffix:

var myhiddenfield = document.querySelectorAll("[id$=_myhiddenfield]")[0];
myhiddenfield.style.visibility="hidden";
myhiddenfield.value = <the JavaScript value>;

Any better idea welcome!