twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
Other
20.31k stars 2.26k forks source link

Trim whitespace at the beginning and end of strings. #5799

Closed Bonapara closed 1 month ago

Bonapara commented 5 months ago

Current Behavior

I can create an email that has spaces at the end: "example@test.com "

Desired Behavior

We want to automatically remove spaces at the beginning and end of every field input.

greptile-apps[bot] commented 5 months ago

Disclaimer: This comment was automatically generated with AI. It can give some useful hints as to where to look for, but sometimes it can also give very inaccurate answers so takes this with a pinch of salt :).

To trim whitespace at the beginning and end of strings for user input fields, follow these steps:

  1. Locate DTO Files: The relevant DTO files for user input fields are located in the src/dto directory.

  2. Modify Setters or Validation Decorators: Implement trimming of whitespace in the setters or validation decorators for these fields. For example, in src/dto/UserInput.dto.ts, modify the email field as follows:

import { IsEmail } from 'class-validator';

export class UserInputDTO {
  private _email: string;

  @IsEmail()
  set email(value: string) {
    this._email = value.trim();
  }

  get email(): string {
    return this._email;
  }
}
  1. Repeat for Other Fields: Apply similar changes to other fields in the DTO files where trimming is required.

References

FelixMalfait commented 1 month ago

Should be solved as we added validation on emails! It doesn't trim but displays red borders