Lock: Trim Trailing Whitespace when Pasting Text into Input Fields

Overview

With Lock, is there a way to trim trailing space when pasting text into input fields? So that for example when a user pastes their email address with a trailing space, the space will be trimmed?

Solution

Lock doesn’t provide any out of the box way to manipulate input fields that would make this achievable.

It’s possible to use JavaScript instead to add an onpaste handler to each of the input fields that will trim any pasted text:

  event.preventDefault();
  let pastedText = (event.clipboardData || window.clipboardData).getData("text");
  input.value = pastedText.trim();
});

Add this to the script section of the custom login page.