Error with validation(Angular)


For my current use case I needed to build custom renderers using bootstrap UI. I’ve basically built off of the angular/materialRenderers but have changed the UI aspect and tweaked some parts for my needs. For example, here Is my textRenderer:

import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular';
import { Actions, and, isDateControl, isEnumControl, isStringControl, or, Tester } from '@jsonforms/core';
import { forEach } from 'lodash';

  selector: 'TextControlRenderer',
  template: `
    <div class="mb-2" [hidden]="hidden" [ngStyle]="{'width': '60%'}" *ngIf="getType()==='radio'">
    <div class="form-check" *ngFor="let enum of this.enumArray">
    [formControl] ="form"
    class="form-check-input mt-1">
    <label class="form-check-label">{{enum}}</label>
    <!--     <span *ngIf="shouldShowUnfocusedDescription()">{{description}}</span> -->
     <span class="description">{{description}}</span>
     <span class="error-msg">{{error}}</span>

  <div class= "mb-2" [hidden]="hidden" *ngIf="getType()==='date'">
    <label class="form-control-label inline-block">{{label}}</label>
    [ngStyle]="{'width': '17%'}"
    [formControl] ="form"
        <!--<span *ngIf="shouldShowUnfocusedDescription()">{{description}}</span> -->
     <span class="description">{{description}}</span>
     <span class="error-msg">{{error}}</span>

  <div class= "mb-2" [hidden]="hidden" [ngStyle]="{'width': '60%'}" *ngIf="getType()==='text'">
    <label class="form-control-label inline-block">{{label}}</label>
    (input) ="onChange($event)"
    [id] = "id"
    [formControl] ="form"
        <!--     <span *ngIf="shouldShowUnfocusedDescription()">{{description}}</span> -->
    <span class="description"> {{description}}</span>
    <span class="error-msg" *ngIf="form.invalid">{{error}}</span>
  changeDetection: ChangeDetectionStrategy.OnPush
export class TextControlRenderer extends JsonFormsControl {
  constructor(jsonformsService: JsonFormsAngularService) {

  enumArray : any[] = [];

  getEventValue = (event: any) =>;
  getType = (): string => {
    if (this.uischema.options && this.uischema.options.format) {
      this.enumArray = this.scopedSchema.enum as any[];
      return this.uischema.options.format;

    if (this.scopedSchema && this.scopedSchema.format) {
      switch (this.scopedSchema.format) {
        case 'email':
          return 'email';
        case 'tel':
          return 'tel';
          case 'date':
            return 'date'
          return 'text';
    return 'text';

  getMaxLength() : number{
  if(this.scopedSchema.maxLength !== undefined){
     return this.scopedSchema.maxLength;
   return -1;


export const BootstrapTextControlRendererTester: Tester = and(
// or(  isDateControl, isEnumControl)

I’ve registered it in the renderers array:

 renderers = [
    { tester: rankWith(3, BootstrapTextControlRendererTester), renderer: TextControlRenderer},
    { tester: rankWith(3, BoostrapNumberControlTester), renderer: NumberControlRenderer},
    { tester: rankWith(3, BootstrapTextAreaRendererTester), renderer: TextAreaRenderer},
Here is my jsonform root:

[ajv] = “ajv”

``` Here is my ajv instance:
ajv = createAjv({
    schemaId: 'auto',
    allErrors: true,
    jsonPointers: true,
    errorDataPath: 'property'

I keep getting this error:

core.js:6210 ERROR TypeError: validator is not a function
    at validate (core.js:37:1)
    at (core.js:47:1)
    at (core.js:176:1)
    at JsonFormsAngularService.push.DAox.JsonFormsAngularService.updateCore (jsonforms.service.js:103:1)
    at TextControlRenderer.onChange (textRenderer.ts:74:27)
    at TextControlRenderer_div_2_Template_input_input_3_listener (textRenderer.ts:47:5)
    at executeListenerWithErrorHandling (core.js:15279:1)

This is happening for all my custom controls, and is also happening when I unregister my controls in the renderer[] and use the default material renderers. However when I change validationMode = “noValidation” on my jsonform root it works as expected. So there is some error happening when trying to validate my formcontrols.
Thanks for your time

Hi @Jayrack813,

The validator is the function which is generated by Ajv when its compile method is called. Something is going wrong here with the custom AJV instance. The reason noValidation “works” is because then AJV is completely ignored.

Can you try to reproduce the problem outside of JSON Forms? So check whether your AJV instance works, for example like this:

const validator = ajv.compile(schema);
const errors = validator(data)

Please also check the “Vanilla” AJV, i.e.

const validator  = new Ajv().compile(schema)

Please also note that the options you hand over to AJV are outdated, please see here.