Field for internal and external links

It would be great to have a dedicated field that allows users to select an internal record or add an external URL.

Currently, to achieve this with the existing options, we are using multiple fields (see the attached screenshot). While our solution works, it feels a bit hacky because we have a boolean field (is_external_link) that isn’t actually necessary (we are using it for the conditional fields plugin). Additionally, it is not possible to make either the internal_link or external_url fields required.

Is this something you plan to implement as a dedicated field in the future? Or do you have any suggestions for a better workaround?

Hey @kevin,

This plugin by our helpful community member @ColinDorr might be just the ticket! Showcase: Better Linking - Plugin

I don’t think we can add this to our native “Link” field functionality because that would break the backward compatibility of the data type.

Right now it’s just an record ID (or an array of them), like ‘abcdefg123’, etc. If suddenly it became an external URL like ‘https://www.example.com’, that would break any existing frontends that depend on the old ID-only behavior.

So the way to get around that is to use a more verbose field type, like a JSON field, which is exactly what ColinDorr’s plugin does, e.g.:

"betterlink": {
      "linkType": {
        "label": "Record",
        "value": "record"
      },
      "record": {
        "id": "181054613",
        "title": "Maximizing User Retention: Effective UX Design",
        [...]
      },

Or for a URL, it returns:

{
    "betterlink": {
      "linkType": {
        "label": "URL",
        "value": "url"
      },
      "record": {},
      "asset": {},
      "url": {
        "title": "URL",
        "url": "https://www.example.com"
      },
      "tel": {},
      "email": {},
      "formatted": {
        "isValid": true,
        "type": "url",
        "text": "https://www.example.com",
        "ariaLabel": "https://www.example.com",
        "url": "https://www.example.com",
        "target": "_self",
        "class": null
      },
      "open_in_new_window": false,
      "isValid": true
    }
  },

That way your frontend can determine what kind of link it is and not have to guess based on the content.

1 Like