jsonforms icon indicating copy to clipboard operation
jsonforms copied to clipboard

Allow custom renderers to handle the readonly behaviour.

Open sarathkcm opened this issue 6 months ago • 2 comments

Is your feature request related to a problem? Please describe.

When using a custom textbox renderer and trying to make it readonly via options, JSON forms is disabling the textbox by passing the enabled prop as false to the renderer.

Ideally this should be upto the renderer to decide whether or not to disable the field based on the readonly option.

As discussed here: https://github.com/eclipsesource/jsonforms/issues/2283 -

It seems that the core runtime is converting readonly to enabled/disabled and not the renderer sets, so it's not possible to override this from renderer sets reliably.

https://github.com/eclipsesource/jsonforms/issues/1735#issuecomment-856632817 https://github.com/eclipsesource/jsonforms/blob/master/packages/core/src/mappers/util.ts#L24

Readonly and disabled states are semantically different and has different meanings, behaviour and styles.

Describe the solution you'd like

I would like for a custom renderer to receive the enabled prop based only on the rules and not based on any other options defined for the ui schema element. The custom renderer should be able to recieve the enabled prop as well as the uischema options, global config and then decide how to render the field.

Describe alternatives you've considered

I am considering renaming the option readonly to isReadOnly to avoid the issue in the current version of JSON forms. but would love to see a proper solution than this workaround.

Package

Core

Additional context

Feature request raised as per this comment..

https://github.com/eclipsesource/jsonforms/issues/2283#issuecomment-3182800446

sarathkcm avatar Aug 13 '25 09:08 sarathkcm

Hi @sarathkcm,

You are right, we are mixing the DISABLE/ENABLE rule support of JSON Forms with the readOnly concept of JSON Schema and JSON Forms UI Schemas.

I talked with the team, we agree that it would be nicer to offer both a readOnly as well as a enabled prop to the renderers. If anyone would like to contribute this feature, raise your hand ;) We would like to keep the current behavior as the default for backwards compatibility, however we could make it configurable to completely separate their behavior.

In the meantime I would recommend following your suggestion, i.e. using a different property than readOnly in the UI Schema and letting the custom renderers / HOCs read that property instead.

sdirix avatar Aug 13 '25 09:08 sdirix

Thank you for the response @sdirix . I raised this issue as @lucas-koehler suggested in the linked issue. Just wanted to bring this to your attention for discussion.

For now I will update the property name, and re-map it to readonly from an HOC so I don't have to update all renderer logic.

If anyone would like to contribute this feature, raise your hand ;)

I really would've if I had some free time :)

Though it would be nice if the team has any ideas or pointers on the approach that needs to be taken to contribute to this feature, so that if not me someone else stumbling on this can take it up if interested,

sarathkcm avatar Aug 13 '25 10:08 sarathkcm