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

Conditional Required in Schema form #939

Open
sonikritika569 opened this issue Nov 16, 2017 · 5 comments
Open

Conditional Required in Schema form #939

sonikritika569 opened this issue Nov 16, 2017 · 5 comments

Comments

@sonikritika569
Copy link

I have to handle a scenario where I have some fields in my form if any of them is filled other all fields become required.
Is there any way by which we can mark conditional Required in such scenario?

@yourarj
Copy link

yourarj commented Nov 21, 2017

Namaste @sonikritika569 ,
Kindly check the contributing.md file before submitting a bug. This seems some logical problem not an issue in angular-schema-form. Kindly check stackoverflow for more relevant problems and solutions.

@Anthropic
Copy link
Member

@sonikritika569 you can do this using the calculate add-on to set a value which you then add to the condition on all fields which you want to show to make them show.

@brunodymios
Copy link

brunodymios commented Jan 14, 2018

@sonikritika569 try to check the example "Hack: Conditional required" in the examples page http://schemaform.io/examples/bootstrap-example.html. Basically, for each conditionally required field you have two versions of it, with the same key.
It may be very useful to support a "requiredIf" key in the schema that accepts a condition-like formula to better manage these situations that are very common. This require an add-on.

@Anthropic do you think it would be easier to edit the current "required" schema key in order to support an array of objects? In each of them we would specify the key of the field and a condition that make it required.

Thank You

@Anthropic
Copy link
Member

@brunodymios the required property of the schema is defined by the json-schema standard. I am looking at adding in a rule processing capability in future that can masse-update required, visible and disabled states for fields based on rules. but it could be a long time coming.

@brunodymios
Copy link

@Anthropic Thank You.
I did some research after writing and I noticed that indeed in the official specification of the standard there is no way to specify such validations. It could be a nice proposal for a future release of the standard, because they are very commonly requested. Extending your library this way could result in inconsistencies when used with other json schema validator (e.g. for server-side validations).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants