angular-schema-form icon indicating copy to clipboard operation
angular-schema-form copied to clipboard

Conditional Required in Schema form

Open sonikritika569 opened this issue 8 years ago • 5 comments

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?

sonikritika569 avatar Nov 16 '17 04:11 sonikritika569

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.

yourarj avatar Nov 21 '17 05:11 yourarj

@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.

Anthropic avatar Nov 21 '17 10:11 Anthropic

@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

brunodymios avatar Jan 14 '18 09:01 brunodymios

@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.

Anthropic avatar Jan 22 '18 04:01 Anthropic

@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).

brunodymios avatar Jan 23 '18 10:01 brunodymios