Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support readOnly and writeOnly attribute of json-schema #33

Closed
domhaas opened this issue May 7, 2020 · 8 comments
Closed

Support readOnly and writeOnly attribute of json-schema #33

domhaas opened this issue May 7, 2020 · 8 comments
Labels
json-schema-spec Relates to official JSON-Schema Spec. schema-keyword Relates to UI-Schema keywords or official JSON-Schema
Projects
Milestone

Comments

@domhaas
Copy link
Contributor

domhaas commented May 7, 2020

Scope of required: per design system/widget

  • DS-Material
  • DS-Bootstrap
  • DS-Blueprint

Summary

We should support the "readOnly" Attribute of the json schema to allow disabling of controls:
https://github.com/json-schema-org/json-schema-spec/blob/master/meta/meta-data.json#L24-L27

Examples

My current implementation in ds-blueprint:

Screenshot_2020-05-07  domhaas ds-blueprint 0 0 15 Demo

As readOnly means you cannot modify an input, I make use of the "disabled" attribute on the blueprintjs-components:

const readOnly = schema.get('readOnly') === true
(...)
<RendererComponent
  (...)
  disabled={readOnly}
/>

Example-Implementation

Motivation

@elbakerino
Copy link
Member

elbakerino commented May 7, 2020

Oh thats a good point!

I got a few ideas/thoughts here:

  • readOnly restricts that the a value can not be changed
    • how does this influence default?
    • text fields need to support disabled, but what for e.g. GenericList
    • should the store be readOnly aware? so it simply is impossible to change those values?
      • but this could be a really tricky thing with allOf and default
    • should it be possible to render something completely different for read only?
      • e.g. a table would make sense for a read only GenericList/SimpleList
  • writeOnly restricts that the widget does not display it's value, but can change it
    • should the widget get the value (the changed value is needed no matter how) or only something like isNotEmpty
    • use case password change: the widget will never receive the value, but it should know there is already an active password
    • how should it be validated when the actual value is never available in the client (e.g. password)

@elbakerino elbakerino changed the title Support "readOnly" attribute of json-schema Support readOnly and writeOnly attribute of json-schema May 7, 2020
@domhaas
Copy link
Contributor Author

domhaas commented May 8, 2020

Oh thats a good point!

I got a few ideas/thoughts here:

* `readOnly` restricts that the a value can not be changed
  
  * how does this influence `default`?
  * text fields need to support `disabled`, but what for e.g. `GenericList`
  * should the store be `readOnly` aware? so it simply is impossible to change those values?
    
    * but this could be a really tricky thing with `allOf` and `default`
  * should it be possible to render something completely different for read only?
    
    * e.g. a table would make sense for a read only `GenericList`/`SimpleList`

* `writeOnly` restricts that the widget does not display it's value, but can change it
  
  * should the widget get the value (the changed value is needed no matter how) or only something like `isNotEmpty`
  * use case password change: the widget will never receive the value, but it should know there is already an active password
  * how should it be validated when the actual value is never available in the client (e.g. password)

Good points. I think we should check out some comparable libraries how they implemented those two attributes.
Also I'm going to get some more information on those questions at the json-schema-repo.

@carolinholat carolinholat added this to To do in ui-schema May 9, 2020
@elbakerino elbakerino added json-schema-spec Relates to official JSON-Schema Spec. schema-keyword Relates to UI-Schema keywords or official JSON-Schema labels May 10, 2020
@elbakerino
Copy link
Member

react-jsonschema-form:

  • AltDateWidget in this lines when readonly the setters are disabled
  • ArrayField here disabled is used for input buttons when readonly
  • TextWidget disabled on textfield, no onChange checks

Not so many support readonly, in a few i didn't found the actual implementation.

writeOnly was in no other project repository

@domhaas
Copy link
Contributor Author

domhaas commented May 10, 2020

I've checked several Libs in different languages. "writeOnly" is indeed completely ignored.
"readonly" has quiet always the same scheme: Disable the main-controls and their children and show it to the user.

My proposition on controls with readOnly:

  • stop interaction
  • show it to the user (gray out)

I don't think we need to go further and build also checks inside the store that really nobody can change any readOnly-Value.
If somebody wants to hack values in the frontend, he simply can do it, whatever we implement to avoid that.

@domhaas
Copy link
Contributor Author

domhaas commented Jun 22, 2020

@elbakerino Update to writeOnly-Attribute:
Like mentioned here writeOnly means really that you cannot read what you write.
The main use-case would be to make a password-input not readable (****).

I'm going to implement that in ds-bootstrap.

@elbakerino
Copy link
Member

readOnly is implemented in ui-schema/ds-material in 0.2.1.

For SimpleList/GenericList only for the array level, if also the values must be read only, the keyword must be set on all.

Doesn't do anything for object.

@elbakerino
Copy link
Member

Further optimized readOnly with #173 for ds-material selections / options.

@elbakerino
Copy link
Member

elbakerino commented Mar 23, 2022

New readOnly options using read-or-write, see #78 for further details,

writeOnly is only good in UI for special use cases, it is best to add own widgets/plugins/validators - as the "what and how" is too complex to abstract by a standard in this library.

ui-schema automation moved this from To do to Done Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
json-schema-spec Relates to official JSON-Schema Spec. schema-keyword Relates to UI-Schema keywords or official JSON-Schema
Projects
ui-schema
  
Done
Development

No branches or pull requests

2 participants