-
Notifications
You must be signed in to change notification settings - Fork 379
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
Required property is not set if field is conditionally required #1390
Comments
Thank you for your report. We happily would accept a contribution for this. |
@stevenmckinnon In general I think setting the The requested feature here relates to In case you need a solution for right now you can always just write your own custom renderers which set the required prop appropriately. You might also be interested in our support packages which includes prioritization and development of requested features. |
Good to know, thanks @sdirix! |
Hey there, we stumbled upon the exact same issue of properties becoming required via some conditions. Whether that is directly in the "root" schema or in some nested anyOf|oneOf|allOf section. And unfortunately the renderers property I highly appreciate this feature being supported. To find out whether a component shall become required or not, if it just got mounted because of some layout condition which is now met, we came up with the following workaround: mounted() {
const validate = this.$validate(this.ajv, this.jsonforms.core.data, this.jsonforms.core.schema);
this.isRequired = validate.errors.some(({ keyword, params }) => {
return keyword === 'required' && params.missingProperty === this.control.path;
});
} |
Hi @nmaier95, I don't see this feature implemented generically soon. We can't really reuse AJV as in the example code as then We would need to evaluate the If you need something like this right now then you probably have some very specific structures you need to see supported. For now I would like to suggest to implement the support for them on your own. Of course we're open for a generic solution but it should be something without too much of a runtime penalty for this "small" feature. |
This won't work. When you fill field property the required property will be set to false since there will be no more errors. IMO the problem is with
It just search for up/down schema. Not checked at all |
We just stumble upon this. I think this deserves more attention. The use cases of allOf, if-then-else with |
Hi @melvinkcx, supporting this use case in a built-in manner is far in the future, maybe it will never be added. The main reason is that this requires a conceptual change in JSON Forms from leveraging Ajv for JSON Schema validation to re-implementing all of JSON Schema validation ourselves within JSON Forms. Note that, even if this was implemented, then there would be room for interpretations, e.g. if an array of However what we would like to accomplish much sooner is a more generic customization option to plug-in own functionalities like a "required" determinator. Then users could implement, copy and reuse a determinator which at least partially solves this problem, as there are some cases which seem clearly defined (like your mentioned See PR #2228 for a community contribution which handles some of the dynamic required use cases. We will not merge it in this form, however you can copy and leverage the code in your custom renderers to solve the dynamic required use case for your scenarios / interpretations. If you would like to have the option of plugging in own determinators: We would happily accept a contribution to make this an easy customization, to not require adopters to rebind all/most of the existing renderers. If you, or someone else, is interested in this, please leave us a message here or in the forums to discuss how this should be implemented. |
Hi @sdirix, thank you for your clarification. I agree that it'd be a huge undertaking. I don't have enough knowledge of the inner workings of JSONForms to propose anything, but here's a workaround we use. Since we use ui-schema conditions ( |
Describe the bug
When making the specific field required based on some condition the required property is still false.
To Reproduce
Steps to reproduce the behavior:
{ type: "object", properties: { b: { type: "boolean" }, c: { type: "string", minLength: 1 } }, if: { properties: { b: { enum: [false] } } }, then: { required: ["c"] } }
Expected behavior
After a conditional action the required property of MaterialInputControl to become true.
Browser (please complete the following information):
Used Setup (please complete the following information):
The text was updated successfully, but these errors were encountered: