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”]
[types field='file-doc’ output='raw'][/types]
[/wpv-for-each]
[wpv-for-each field="wpcf-file-excel”]
[types field='file-excel’ output='raw'][/types]
[/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!
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
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!
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.
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