working autocomplete, should implement search

This commit is contained in:
2023-01-23 03:58:39 +01:00
parent 4553cba89f
commit 893013cdae
4 changed files with 66 additions and 93 deletions

View File

@@ -2,9 +2,9 @@ import { FormlyJsonschema } from "@ngx-formly/core/json-schema";
import { FormlyJsonschemaOptions } from "@ngx-formly/core/json-schema/formly-json-schema.service";
import { FormlyFieldConfig } from "@ngx-formly/core";
import { JSONSchema7 } from 'json-schema';
import {JsonschemasService } from "./jsonschemas.service";
import {Observable, map, tap} from "rxjs";
import {Injectable} from "@angular/core";
import { JsonschemasService } from "./jsonschemas.service";
import { Observable, map } from "rxjs";
import { Injectable } from "@angular/core";
@Injectable({
providedIn: 'root',
@@ -14,21 +14,29 @@ export class CrudFormlyJsonschemaService extends FormlyJsonschema {
super();
}
override toFieldConfig(schema: JSONSchema7, options?: FormlyJsonschemaOptions): FormlyFieldConfig {
return super.toFieldConfig(schema, options);
override toFieldConfig(schema: JSONSchema7): FormlyFieldConfig {
let fieldConfig = super.toFieldConfig(schema, new CrudFormlyJsonschemaOptions());
return fieldConfig;
}
getCreateFields(resourceName: string): Observable<FormlyFieldConfig> {
return this.jsonSchemasService.getCreateResource(resourceName).pipe(
map((schemas: any) => this.toFieldConfig(schemas)),
tap(console.log),
)
}
getUpdateFields(resourceName: string): Observable<FormlyFieldConfig> {
return this.jsonSchemasService.getUpdateResource(resourceName).pipe(
map((schemas: any) => this.toFieldConfig(schemas)),
tap(console.log),
)
}
}
export class CrudFormlyJsonschemaOptions implements FormlyJsonschemaOptions {
map = (field: any, schema: any) => {
if (schema.hasOwnProperty('foreignKey')) {
field.foreignKey = schema['foreignKey'];
}
return field;
}
}