Page 1 of 1

Make email field a link

Posted: 08 Aug 2017
by Jaydius
I have a form field that contains an email address. Is there a way to make this a mailto link based on the email address, which will open in the users default mail app?

Re: Make email field a link

Posted: 09 Aug 2017
by Nikita Kurguzov
Hello, Jaydius!
It should happen on its own, you don't need to do anything special. If your text field contains a valid email address, when you open it in Read Only mode, it would automatically generate something like this:

Code: Select all

 <a href="mailto:email@mail.com">email@mail.com</a>
You can check it in the browser's inspector. If this doesn't happen, let us know and post a screenshot, please.

Re: Make email field a link

Posted: 09 Aug 2017
by Jaydius
Nikita Kurguzov wrote:
09 Aug 2017
Hello, Jaydius!
It should happen on its own, you don't need to do anything special. If your text field contains a valid email address, when you open it in Read Only mode, it would automatically generate something like this:

Code: Select all

 <a href="mailto:email@mail.com">email@mail.com</a>
You can check it in the browser's inspector. If this doesn't happen, let us know and post a screenshot, please.
Good day Nikita,

The field is a lookup from a contact list, where the personnel ID matches a contact list ID. The email address field is linked through to the Personnel listing. When displaying this lookup field on the Display form, it only shows it as text, not a link as you stated it should. I was hoping there would be a way to use the content (email address) to build a link from?
Capture.JPG
Capture.JPG (13.82 KiB) Viewed 6910 times

Re: Make email field a link

Posted: 10 Aug 2017
by Nikita Kurguzov
Yes, in case you are using Lookups instead of standard text field, it wouldn't generate this link automatically. Instead, it should generate links to the item itself. Are you saying it's only displaying lookup field as plain text? We need to know it in order to write appropriate code for your case.

Re: Make email field a link

Posted: 10 Aug 2017
by Jaydius
Nikita Kurguzov wrote:
10 Aug 2017
Yes, in case you are using Lookups instead of standard text field, it wouldn't generate this link automatically. Instead, it should generate links to the item itself. Are you saying it's only displaying lookup field as plain text? We need to know it in order to write appropriate code for your case.
Correct, it's only displaying in plain text.

Re: Make email field a link

Posted: 11 Aug 2017
by Nikita Kurguzov
Try using this code in JavaScript editor:

Code: Select all

var myVar = setInterval(myTimer, 100);

function myTimer() {
	var email = fd.field('FieldName').value();
        if (email)
	{
		var string = "<a href=mailto:" + email + ">" + email + "</a>";
		fd.field('FieldName').control()._el().html(string);
		clearInterval(myVar);
	}
}
Sadly, we can't avoid using the Timer here. Replace FieldName with the internal name of the Email field.

Re: Make email field a link

Posted: 13 Aug 2017
by Jaydius
Nikita Kurguzov wrote:
11 Aug 2017
Try using this code in JavaScript editor:

Code: Select all

var myVar = setInterval(myTimer, 100);

function myTimer() {
	var email = fd.field('FieldName').value();
        if (email)
	{
		var string = "<a href=mailto:" + email + ">" + email + "</a>";
		fd.field('FieldName').control()._el().html(string);
		clearInterval(myVar);
	}
}
Sadly, we can't avoid using the Timer here. Replace FieldName with the internal name of the Email field.
Works perfectly. Thank you very much for your help Nikita.