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
[question] Support for const? #1587
Comments
Hi! Thanks for this report. Current state
Automatic generation within JSON Forms
Let me know whether one of the approaches works for you. If you (or someone else 😄) would like to contribute something for this use case: I think a In the meantime we could maybe change the default ui schema generation to also include a control for these |
A case where default is insufficient is where the form requests an array of heterogeneous objects and one wants to label each element by its type: {
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"required": ["@type", "name"],
"properties": {
"@type": {
"type": "string",
"const": "Person"
},
"name": {
"type": "string",
"title": "Person's name"
},
"gender": {
"type": "string",
"enum": ["male", "female", "other", "not disclosed"]
}
}
},
{
"type": "object",
"required": ["@type", "name"],
"properties": {
"@type": {
"type": "string",
"const": "Organisation"
},
"name": {
"type": "string",
"title": "Org's name"
}
}
}
]
}
} If one adds defaults and the user selects Organization and enters "name" only, then ajv will fill in "Person" as the default. This seems to work for me: import React from 'react';
import { withJsonFormsControlProps } from '@jsonforms/react';
export const ConstRenderer = withJsonFormsControlProps(({schema, handleChange, path}) => {
React.useEffect(() => {
handleChange(path, schema['const'])
}, [schema, path]);
return (<React.Fragment></React.Fragment>);
}); |
@sdirix What if you're use-case is for the user to type in the const value? As a simple example, say you wanted the user to type "Confirm". This may not be a great UX design, but I have seen it. My real use-case is I want to create a confirmation field where the user should enter the same value as entered in the previous field. I tried to accomplish this with the schema below, but it creates a enum drop-down like you described in your previous comment.
|
We recently improved some of the Note this only happens on user interactions in which the user triggers the creation of a new object. It's very useful for these "@type" use cases in which a const is used to identify the type of the object. This is available since |
Describe the bug
I am not sure if this is a feature request or a bug. I am trying to pass constant strings from the schema into the JSON output of the form. According to the JSON Schema spec this should be possible by using the "const" keyword. Unfortunately, I cannot get this to work with JSON Forms.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The constant data is passed through from the schema into the output.
Browser (please complete the following information):
Chrome
Used Setup (please complete the following information):
Additional context
I am trying to use JSON Forms to generate valid FHIR healthcare resource output.
The text was updated successfully, but these errors were encountered: