Trim Search Input

Hey @Jon,
Thanks for the mention! Just note that the above code only works in scenarios where you input the text in the search input and then press the Search button separately.

This will not work if you input the text in the search input and press the Enter key, as the input field never loses focus and never triggers the event handler.

You would need a similar event handler that listens for the Enter key being pressed while the input is focused.
This updated code should handle both scenarios, with a shared function:

$(document).on('knack-view-render.any', function(event, view, data) {
  
  // Event handler for blur on input and textarea elements
  $('input[type="text"], textarea').on('blur', function() {
    trimAndUpdateInput($(this)); // Pass $(this) as an argument
  });

  // Event handler for Enter key press on input elements
  $('input[type="text"]').on('keypress', function(event) {
    if (event.keyCode === 13) {
      trimAndUpdateInput($(this)); // Pass $(this) as an argument
    }
  });

});

// Function to trim and update the input value
function trimAndUpdateInput(inputElement) {
  
  var trimmedValue = inputElement.val().trim();
  inputElement.val(trimmedValue);

}