working autocomplete, should implement search
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user