Make email field a link

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Jaydius
Posts: 43
Joined: Thu Nov 12, 2015

08 Aug 2017

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?

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

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.
Cheers

Jaydius
Posts: 43
Joined: Thu Nov 12, 2015

09 Aug 2017

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 6905 times

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

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.
Cheers

Jaydius
Posts: 43
Joined: Thu Nov 12, 2015

10 Aug 2017

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.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

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.
Cheers

Jaydius
Posts: 43
Joined: Thu Nov 12, 2015

13 Aug 2017

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.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests