Skip to content

Commit

Permalink
feat: disableOnEdit Text widget (#3117)
Browse files Browse the repository at this point in the history
* added disableOnEdit for Text widgets

* updated Text widget documentation
  • Loading branch information
kevin-kho authored Aug 20, 2024
1 parent 358e471 commit 8fb0252
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/extensibility/60-form-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 4 additions & 0 deletions public/schemas/schema-form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export function StringRenderer({
required,
placeholder,
originalResource,
editMode,
...props
}) {
const { t } = useTranslation();
const { tFromStoreKeys, t: tExt, exists } = useGetTranslation();
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;
Expand Down Expand Up @@ -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)}
Expand Down

0 comments on commit 8fb0252

Please sign in to comment.