Skip to content

Commit 2e08cd4

Browse files
committed
[form] Make fields of const property readonly
1 parent 2a6d9e3 commit 2e08cd4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

.changeset/rotten-doors-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sjsf/form": patch
3+
---
4+
5+
Make fields of `const` property readonly

packages/form/src/form/context/widget-attributes.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
} from "svelte/elements";
77

88
import type { Nullable } from "@/lib/types.js";
9+
import type { Schema } from '@/core/index.js';
910

1011
import type { Config } from "../config.js";
1112
import { computeId } from "../id-schema.js";
@@ -47,6 +48,12 @@ function inputType(format: string | undefined) {
4748
}
4849
}
4950

51+
function isReadonly(
52+
schema: Schema
53+
) {
54+
return schema.readOnly || schema.const !== undefined;
55+
}
56+
5057
export function inputAttributes(
5158
ctx: FormContext,
5259
{ idSchema, required, schema, uiOptions }: Config,
@@ -70,6 +77,7 @@ export function inputAttributes(
7077
list: Array.isArray(schema.examples)
7178
? computeId(idSchema, "examples")
7279
: undefined,
80+
readonly: isReadonly(schema),
7381
oninput: handlers.oninput,
7482
onchange: handlers.onchange,
7583
onblur: handlers.onblur,
@@ -94,6 +102,7 @@ export function textareaAttributes(
94102
required,
95103
minlength: schema.minLength,
96104
maxlength: schema.maxLength,
105+
readonly: isReadonly(schema),
97106
oninput: handlers.oninput,
98107
onchange: handlers.onchange,
99108
onblur: handlers.onblur,

0 commit comments

Comments
 (0)