Hi everyone,
I’m working with a standalone Angular 18 application and I want to integrate JSONForms. However, I don’t want to use Material UI. Instead, I’ve created my own custom input component.
For example, here’s how my input component looks:
html
<our-input
[formControl]="form"
[type]="'text'"
[label]="'test'"
></our-input>
Now, I’d like to render a form using a JSON schema and UI schema, but have it use my custom component instead of Material inputs.
How can I configure JSONForms to use this component when rendering fields like this?
here is just as example my schema and UIschema
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"birthDate": {
"type": "string"
},
"occupation": {
"type": "string"
}
}
}
{
"type": "VerticalLayout",
"elements": [
{
"type": "HorizontalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/name"
},
{
"type": "Control",
"scope": "#/properties/birthDate"
},
{
"type": "Control",
"scope": "#/properties/occupation"
}
]
}
]
}
and here is my tester
import { rankWith, schemaTypeIs } from '@jsonforms/core';
export const insureInputTester = rankWith(
5, // must be > 1
schemaTypeIs('string'),
);
here i get the static schema and uischema as example
import schemaAsset from './schema.json';
import * as test from './uischema.json';
export class FormsComponent implements OnInit {
private readonly http = inject(HttpClient);
data: any;
customRenderers: any[] = [
{ tester: insureInputTester, renderer: FormTypesComponent },
];
ngOnInit(): void {
this.http.get('assets/data.json').subscribe((data: any) => {
this.data = data;
console.log('Data loaded:', this.data);
});
}
onSubmit(): void {
console.log('Form values:', this.data);
}
onDataChange(newData: FormData): void {
console.log('Data changed:', newData);
console.log('Debug: onDataChange triggered');
this.data = newData;
}
}
here is html of FormsComponent
@if (data && schema && uischema) {
<jsonforms
[data]="data"
[schema]="schema"
[uischema]="uischema"
[renderers]="customRenderers"
(dataChange)="onDataChange($event)"
></jsonforms>
}
<button (click)="onSubmit()">Submit</button>
here is rederer component
@Component({
selector: 'form-management-form-types',
standalone: true,
imports: [ReactiveFormsModule],
templateUrl: './form-types.component.html',
styleUrl: './form-types.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FormTypesComponent extends JsonFormsControl {
constructor(jsonFormsService: JsonFormsAngularService) {
super(jsonFormsService);
console.log('FormTypesComponent initialized');
}
}
and here is html of FormTypesComponent
<our-input
[formControl]="form"
[type]="'text'"
[label]="'test'"
></our-input>
I tried setting it up, but after running the app, I see the following message on the page:
No applicable renderer found.
I assume it’s not picking up my custom renderer correctly. How can I register or bind my custom component so JSONForms recognizes and uses it?