Skip Navigation

[Resolved] Split: Show Repeating Fields in Javascript Editor

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by eloiD 5 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#1160571

Thank you so much,
I have another question:

May I show Repeating Fields in Javascript Editor (View)?

#1160586

Hi,

Thanks for asking! I'd be happy to help.

To get the values from the single or repeating fields, you can use shortcode or PHP code as explained in these guides:
https://toolset.com/documentation/customizing-sites-using-php/functions/
https://toolset.com/documentation/user-guides/repeating-fields/

But, unfortunately, both the shortcodes or the PHP code can't be directly used in the View's "JS editor" tab.

To use those values in the custom javascript code, you can follow these steps:

1. You can first print the required field's value in the HTML of your view's "Loop Editor" or the "Content Template", wrapped in a special container with a unique ID, e.g.


<span id="special-field-container">[types field="my-field-slug" separator=","][/types]</span>

2. Next, in the "JS editor" tab, you'll be able to get the value from that specific span tag, using the code:


jQuery( document ).ready(function() {
      var fieldval = jQuery('span#special-field-container').text();
      alert(fieldval);
});

Note: As needed, you can also include some custom CSS code to hide that special span tag, so that the field value is not visible to the visitors on the front-end.

I hope this helps.

regards,
Waqar

#1161332

My issue is resolved now. Thank you!