Link custom user field to external website

(Denis Heraud) #49

Also today I realized that the User Profile page actually displays the custom field as it should, although compared to the user card, now the custom field (Website) is displayed last instead of first…


1 Like

I feel like I’ve seen a discussion of this, but I can’t find it now.

I’ve got a custom profile field that holds a user’s website implemented using this tutorial, but allowing for any external site to be entered, rather than just linking to Twitter or something. The problem I have is that about 80% of the users don’t bother to put “http(s)://” in front of the URL they enter. They (rightly) expect that “” should just work. So how do I make it just work?

Edited to add: Figured it out. Below is the entire if block of javascript I used to determine whether to attempt to show an external link. The inner if is what determines whether the external URL needs to have “http” added to it, and takes care of doing it.

    if (userFields && userFields[churchURLFieldId]) {
      const rawChurchURL = userFields[churchURLFieldId];
      var url = rawChurchURL;
      if (!/^https?:\/\//i.test(rawChurchURL)) {
        url = 'http://' + rawChurchURL;
      const link = "<a href='"+url+"' target='_blank'>"+userFields[churchNameFieldId];+"</a>";
      return Ember.Object.create({ link, name: churchURL.get('name') });
    } else {
      return null;