Skip Navigation

[Resolved] Reopening ticket Add target="_blank" to repeating fields

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 4 replies, has 2 voices.

Last updated by cna-serviziS 1 year, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2467081
Schermata 2022-09-29 alle 09.48.39.png
Schermata 2022-09-29 alle 09.48.25.png

Hi there,
I'm reopening the ticket https://toolset.com/forums/topic/add-target_blank-to-repeating-fields/#post-2465689
because on a page that's built basically the same way, I have also other file types (doc, xls) with classes "special-link-doc" and "special-link-xls" .
For these I tried to edit the code your supporter Waqar gave me:

[wpv-for-each field="wpcf-file-doc”]
<a class="special-link-doc” href="[types field='file-doc’ output='raw'][/types]" target="_blank">[types field='file-doc’ output='raw'][/types]</a>
[/wpv-for-each]

[wpv-for-each field="wpcf-file-excel”]
<a class="special-link-xls” href="[types field='file-excel’ output='raw'][/types]" target="_blank">[types field='file-excel’ output='raw'][/types]</a>
[/wpv-for-each]

It's not working though, showing a blank line..maybe because it's supposed to display these in a sequence but the code is not "telling this to the system"?
Could you please look into this? Access is the same as previous ticket
This is the page: hidden link
Screenshots to clarify.
thank you!

#2467261

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

I checked the view and noticed that the conditional block for the "File DOC" field in the first view, was not functioning correctly. The most likely cause could be some invalid character code while copying/pasting the code.

I removed that conditional block and the enclosed repeating field block, added it again, and used the following custom code in the settings for the 3 repeating field blocks, and the icon and the links seem to be working now:


[wpv-for-each field="wpcf-file-doc"]
    <a class="special-link-doc" href="[types field='file-doc' output='raw'][/types]" target="_blank">[types field='file-doc' output='raw'][/types]</a>
[/wpv-for-each]


[wpv-for-each field="wpcf-file-excel"]
    <a class="special-link-xls" href="[types field='file-excel' output='raw'][/types]" target="_blank">[types field='file-excel' output='raw'][/types]</a>
[/wpv-for-each]


[wpv-for-each field="wpcf-file-pdf"]
    <a class="special-link-pdf" href="[types field='file-pdf' output='raw'][/types]" target="_blank">[types field='file-pdf' output='raw'][/types]</a>
[/wpv-for-each]

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2467265
Schermata 2022-09-29 alle 15.21.58.png

Thank you again, Waqar.
Only when I open the editor of the page the blocks seem to encounter an error (it's happened ever since adding the custom code). If I click on the "Attempt to restore the block" button, it goes away. But I'm wondering if it's ok like that (see screenshot).

Thank you!

#2469211

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

I can think of another alternate, that will not involve adding custom code in the "Repeating Field" block, which is causing this error.

You can set the "Display Mode" option back to "Separated by" (from "Custom"), the way it was before. And in the "File link extra classes" field of the block, you can include one extra class "new-tab-link", so that all these links can be targeted through a single common class.

For example:

For docs links, these will be the two classes:
special-link-doc new-tab-link

For xls links, these will be the two classes:
special-link-xls new-tab-link

For pdf links, these will be the two classes:
special-link-pdf new-tab-link

After that, you can include the following custom script in the View block's "Custom JS" field:


jQuery(document).ready(function( $ ) {
	$('a.new-tab-link').attr('target','_blank');
});

This link will find all the links on the page with the class "new-tab-link" and add the target="_blank" attribute to them.

#2469981

Thank you, Waqar, always helpful.
It turns out your last solution works well but conflicts with my our caching plugin.. I'll stick with the first solution for the moment.

Have a great day

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.