SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.17k stars 660 forks source link

Validation errors are not displayed #1158

Closed IrynaMatviichuk closed 2 years ago

IrynaMatviichuk commented 2 years ago

Describe the bug I use adminjs with TypeOrm and when I try to save the wrong data, TypeOrm throws an error but this error is not displayed in adminjs.

You can see how this validation error looks in the console on the first screenshot. As you can see the field name of this error is undefined. And there are no errors displayed near 'code' field.

Installed libraries and their versions

Expected behavior I expect to receive errors object with correct field name and have these errors displayed

Screenshots image

image

AdminJSOptions with schema

          {
            resource: Language,
            options: {
              properties: {
                code: { isTitle: true },
              },
            },
          },
import {
  Column,
  Entity,
  OneToMany,
  PrimaryGeneratedColumn,
  BaseEntity,
} from 'typeorm';
import { Translation } from './translation.entity';

@Entity()
export class Language extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 2, unique: true })
  code: string;

  @OneToMany(() => Translation, (translation) => translation.language)
  translations: Translation[];
}
dziraf commented 2 years ago

@IraMatviichuk I've just checked and QueryFailedError doesn't give an information which exact field had an error plus SQL Driver generated message isn't something we should be showing to the end user.

I think your best bet would be to use class-validator to set validation rules for your entities as it's integrated with @adminjs/typeorm.

Aidan-IconX commented 1 month ago

Getting same issue with and without class-validator. Using typeorm. If a field is required on a create new entry form, a message is shown "There are validation errors - check them out below" - but nothing is shown on the web page, in the web page console logs, in the network traffic, or in the adminjs logs.