jsonforms icon indicating copy to clipboard operation
jsonforms copied to clipboard

Errors are not emitted on initial init for Angular

Open jpuvogel13 opened this issue 3 years ago • 0 comments

### Describe the bug

When the form renders, the initial errors are not output from the init call. Please look at the documentation here from: packages/angular/src/jsonforms-root.component.ts:

ngOnInit(): void { this.jsonformsService.init({ core: { data: this.data, uischema: this.uischema, schema: this.schema, ajv: this.ajv, validationMode: this.validationMode, additionalErrors: this.additionalErrors }, uischemas: this.uischemas, i18n: this.i18n, renderers: this.renderers, config: this.config, readonly: this.readonly });

Therefore when the form loads, the error array is empty UNTIL the user triggers onChange() on one of the input fields. Once the onChange() is called, the errors array is filled.

Expected behavior

The errors should be output in the initial init call. In my situation, I don't want the user to be able to submit the form until required fields are filled in. I do this by checking if the errors array is empty, then allow submittal. However, the user is able to submit the form if they don't touch any fields and just hit submit (because the errors array is empty).

Steps to reproduce the issue

  1. Render a schema, with at least one required field.
  2. Listen to the errors prop, and set errors array to local variable in parent component: (errors)="onErrors($event)"

onErrors(event: any){ this.errorsArray = event; console.log("ERRORS", this.errorsArray); }

  1. Notice on the intial rendering, the log statement will produce an empty array: [ ].

Screenshots

No response

In which browser are you experiencing the issue?

Google Chrome

Framework

Core, Angular

RendererSet

Other (please specify in the Additional context field)

Additional context

I have created my own custom renderers, which are essentially Angular Material Renderers with bootstrap in the template.

jpuvogel13 avatar Jul 08 '22 17:07 jpuvogel13