Trim on presave (rather than validate) so input is treated consistently whether through a form or API (such as feeds)

Created on 27 December 2020, over 4 years ago
Updated 1 May 2024, 11 months ago

Problem/Motivation

A value can also be imported by code, not only using the form. That code may have trailing spaces.
Why not trim on presave(), then?

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇮🇱Israel Amir Simantov

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States mlncn Minneapolis, MN, USA

    I think this is a good idea! Would welcome a patch, ideally we can still be compatible with the feature request Alert people when their text is trimmed Active

  • 🇺🇸United States mlncn Minneapolis, MN, USA

    One issue here is we want the trimming to happen before any other validation (at least, that is what makes sense in most use cases i have used this for or can think of), and presave happens after.

    For example, if we trim a blank-spaces-only input down to nothing, that should trigger the warning on required field.

    And if we clean up easy things without the person submitting the form having to do the cleanup (no leading or trailing spaces would be a reasonable constraint to have in custom logic apart from what trim does, but more than that requiring a phone number or identifying string to match a format or number of characters is common validation) and presave would force the form filler or API provider to clean up the data first as the validation would reject it before presave could happen.

    We could do both, but there really should be a way to do pre-validation cleanup for both form and API data in a consistent way.

Production build 0.71.5 2024