From 8fb0252f15a9d6b300f43cebb3b0a1155b8b0b7c Mon Sep 17 00:00:00 2001 From: kevin-kho Date: Mon, 19 Aug 2024 23:58:30 -0700 Subject: [PATCH] feat: disableOnEdit Text widget (#3117) * added disableOnEdit for Text widgets * updated Text widget documentation --- docs/extensibility/60-form-widgets.md | 1 + public/schemas/schema-form.yaml | 4 ++++ .../Extensibility/components-form/StringRenderer.js | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/extensibility/60-form-widgets.md b/docs/extensibility/60-form-widgets.md index 15313bc485..73aebfea66 100644 --- a/docs/extensibility/60-form-widgets.md +++ b/docs/extensibility/60-form-widgets.md @@ -37,6 +37,7 @@ These are the available `Text` widget parameters: | **readOnly** | No | boolean | Specifies if a field is read-only. Defaults to `false`. | | **decodable** | No | boolean | Specifies that the field is base64-encoded and can be decoded in the UI. It can't be used together with **enum**. | | **decodedPlacehoder** | No | string | An optional alternative placeholder to use when the field is decoded. | +| **disableOnEdit** | No | boolean | Disables a field in edit mode, defaults to `false`. Ignored if **readOnly** is set to `true`. | See the following examples: diff --git a/public/schemas/schema-form.yaml b/public/schemas/schema-form.yaml index 1607e20263..3191ea295e 100644 --- a/public/schemas/schema-form.yaml +++ b/public/schemas/schema-form.yaml @@ -308,3 +308,7 @@ $widgets: decodedPlaceholder: type: string description: optional alternative placeholder to use when the field is decoded + disableOnEdit: + type: boolean + description: a boolean which specifies if field is disabled on edit. + default: false diff --git a/src/components/Extensibility/components-form/StringRenderer.js b/src/components/Extensibility/components-form/StringRenderer.js index 4ebac988b2..14e623dd01 100644 --- a/src/components/Extensibility/components-form/StringRenderer.js +++ b/src/components/Extensibility/components-form/StringRenderer.js @@ -19,6 +19,7 @@ export function StringRenderer({ required, placeholder, originalResource, + editMode, ...props }) { const { t } = useTranslation(); @@ -26,6 +27,7 @@ export function StringRenderer({ const schemaPlaceholder = schema.get('placeholder'); const readOnly = schema.get('readOnly') ?? false; const decodable = schema.get('decodable'); + const disableOnEdit = schema.get('disableOnEdit'); const [decoded, setDecoded] = useState(true); let decodeError = false; @@ -142,7 +144,7 @@ export function StringRenderer({ }, }); }} - disabled={readOnly} + disabled={readOnly || (disableOnEdit && editMode)} isListItem={props.isListItem} label={tFromStoreKeys(storeKeys, schema)} data-testid={storeKeys.join('.') || tFromStoreKeys(storeKeys, schema)}