Page 1 of 1
turn a lookup filed to email clickable link
Posted: 2023-05-18 07:26
by ushay
hello friend,
i have a lookup in my table to a filed that contains an email address, i have managed to format the value of the filed to an Emil Link and it is working inside the lookup:

- emailLink.PNG (20.3 KiB) Viewed 3987 times
is it possible to turn the text of the field outside to be clickable as well?

- emailLink2.PNG (10.26 KiB) Viewed 3987 times
shay.
Re: turn a lookup filed to email clickable link
Posted: 2023-05-18 08:00
by pbottcher
Hi,
you can use javascript to change the text into a clickable text.
Re: turn a lookup filed to email clickable link
Posted: 2023-05-18 09:06
by ushay
OK, but where should i do it? in table-dv.js? can u please share an example?
thank you.
Re: turn a lookup filed to email clickable link
Posted: 2023-05-18 14:21
by pbottcher
Hi,
looking at the image you shared, yes, table-dv.js should work.
You may try something like
Code: Select all
$j('#FIELDNAME').wrap('<a id="FIELDNAME-mailto"><a>');
$j('#FIELDNAME-mailto').attr('href','mailto:'+$j('#FIELDNAME').text());
replace FIELDNAME with our valid fieldname
Re: turn a lookup filed to email clickable link
Posted: 2023-05-18 15:43
by ushay
Thanks, i tried it with my field name 'email3':
Code: Select all
$j('#email3').wrap('<a id="email3-mailto"><a>');
$j('#email3-mailto').attr('href','mailto:'+$j('#email3').text());
i even tried this in table.php in table_dv():
Code: Select all
<script>
$j(function() {
var email = $j("#email3").text().trim();
if (validateEmail(email)) {
var emailLink = $j("<a>").attr("href", "mailto:" + email).text(email);
$j("#email3").empty().append(emailLink);
}
});
function validateEmail(email) {
var re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
</script>
but no luck.
Re: turn a lookup filed to email clickable link
Posted: 2023-05-18 17:53
by pbottcher
Is your field email3 readonly on the page?
Do you see any error in the develper console?
The code in the table_dv looks a bit strange.
I quickly set up a test with
Code: Select all
$j('#email3').wrap('<a id="email3-mailto"><a>');
$j('#email3-mailto').attr('href','mailto:'+$j('#email3').text());
and it works fine.
Re: turn a lookup filed to email clickable link
Posted: 2023-05-18 18:47
by ushay
hi,
it is a lookup field , not read-only.
when i add the code you suggested , the email address disappear

- 2023-05-18 212138.png (209.82 KiB) Viewed 3956 times
Re: turn a lookup filed to email clickable link
Posted: 2023-05-18 19:28
by pbottcher
Hi,
well than it is a different story.
You may try
Code: Select all
setTimeout(change_mail,1000);
function change_mail () {
$j('#email3').wrap('<a id="email3-mailto"><a>');
$j('#email3-mailto').attr('href','mailto:'+$j('#email3').text())
}
Re: turn a lookup filed to email clickable link
Posted: 2023-05-19 05:13
by ushay
excellent
thank you very much, it works .