make non-fillable fields visible but disabled in UI

This commit is contained in:
dswbx
2025-10-24 14:07:37 +02:00
parent 292e4595ea
commit f2aad9caac
11 changed files with 353 additions and 37 deletions

View File

@@ -26,11 +26,19 @@ export const baseFieldConfigSchema = s
.strictObject({
label: s.string(),
description: s.string(),
required: s.boolean({ default: false }),
fillable: s.anyOf([
s.boolean({ title: "Boolean" }),
s.array(s.string({ enum: ActionContext }), { title: "Context", uniqueItems: true }),
]),
required: s.boolean({ default: DEFAULT_REQUIRED }),
fillable: s.anyOf(
[
s.boolean({ title: "Boolean" }),
s.array(s.string({ enum: ["create", "update"] }), {
title: "Context",
uniqueItems: true,
}),
],
{
default: DEFAULT_FILLABLE,
},
),
hidden: s.anyOf([
s.boolean({ title: "Boolean" }),
// @todo: tmp workaround
@@ -103,7 +111,7 @@ export abstract class Field<
return this.config?.default_value;
}
isFillable(context?: TActionContext): boolean {
isFillable(context?: "create" | "update"): boolean {
if (Array.isArray(this.config.fillable)) {
return context ? this.config.fillable.includes(context) : DEFAULT_FILLABLE;
}
@@ -165,7 +173,7 @@ export abstract class Field<
// @todo: add field level validation
isValid(value: any, context: TActionContext): boolean {
if (typeof value !== "undefined") {
return this.isFillable(context);
return this.isFillable(context as any);
} else if (context === "create") {
return !this.isRequired();
}