ID for a field in multified | Community
Skip to main content
Level 6
Mar 16, 2021 1:51 PM UTC
Solved

ID for a field in multified

I have a textfield within a multified. I need to fetch the ID for the textfield each item a new multified item is added. Since the textfield is within the multified I am not sure how can i set the granite:id to it. Any suggestion?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Rohit_Utreja
Rohit_UtrejaAccepted solution
New Participant
Mar 16, 2021 3:38 PM UTC

@shaheena_sheikh ,

 

You can try to iterate the textfield inside the multifield using clientlibs javascript.

These Ids will be generated by granite UI and can be iterated through the code.

 

Adding a sample code to fetch values from dialogs using JS.

 

https://github.com/viji13/aemlearnings/blob/master/clientlibs/script.js

 

5 replies

Kiran_Vedantam
New Participant
Mar 17, 2021 6:32 AM UTC

Hi @shaheena_sheikh,

 

You can achieve this in two ways

  1. Writing BE event listeners who listen to the JCR level events and dynamically add an ID [property] as per your prescribed format to the node
  2. Write FE javascript code on the dialog level to dynamically add the ID whenever the text field is authored.

For more details on event listeners check my blog here

 

Hope this helps.

 

Thanks,

Kiran Vedantam.

Translate
Anudeep_Garnepudi
New Participant
Mar 17, 2021 4:54 AM UTC

@shaheena_sheikh 

ID must be unique, if you have text field with id(granite:id) in side multifield, there will be multiple elements with same id. You will always get the first element.

So use class(granite:class) instead and get the last element(selector text-field-class:last) of that class when new item is added. 

Example:

Add class(granite:class) to id text field (here I am using id-text-field). Try below code to get each text field value inside multifield.

$(".coral3-Multifield-item").each(function( index ) { console.log($(this).find(".id-text-field").val()); });

 

Translate
Level 6
Mar 17, 2021 6:16 AM UTC
so, if I have 4 multifield items how can i get the data for each textfield in each item?
Translate
Rohit_Utreja
Rohit_UtrejaAccepted solution
New Participant
Mar 16, 2021 3:38 PM UTC

@shaheena_sheikh ,

 

You can try to iterate the textfield inside the multifield using clientlibs javascript.

These Ids will be generated by granite UI and can be iterated through the code.

 

Adding a sample code to fetch values from dialogs using JS.

 

https://github.com/viji13/aemlearnings/blob/master/clientlibs/script.js

 

Translate