Open chaitrali-r opened 1 year ago
Conditional Fields Support will be added for : -
This is example for understanding how it will work:
Development Approach :-
{ type: 'textfield', key: 'firstName', label: 'First Name', conditional: { show: true, // or false to hide the field when: 'age', // the field that triggers the condition eq: '18' // the value that triggers the condition } }
Once the conditional fields are added to the Formio object, it is needed to convert it into JSON Schema format to handle dependent and nested fields.
For dependent fields, use the 'anyOf' keyword in JSON Schema to define the condition and required fields.
Sample code for dependent fields in JSON Schema format:
{ "type": "object", "properties": { "firstName": { "type": "string", "title": "First Name" }, // Other properties... }, "required": [ // List of required properties... ], "anyOf": [ { "properties": { "age": { "const": "18" } }, "required": [ "firstName" ] }, { "required": [] } ] }
For nested fields, the JSON Schema format is needed to define the nested structure and include the conditional logic within the nested objects.
Sample code for nested fields in JSON Schema format:
{ "type": "object", "properties": { "person": { "type": "object", "properties": { "firstName": { "type": "string", "title": "First Name" }, // Other properties... }, "required": [ // List of required properties... ], "anyOf": [ { "properties": { "age": { "const": "18" } }, "required": [ "firstName" ] }, { "required": [] } ] } } }
By following these steps and incorporating the provided code samples, we can efficiently add conditional fields to your Formio object and convert it into JSON Schema format to handle dependent and nested fields.
@Pratikshakhandagale plzz verify the approch and give suggestions.
How User can Implement Conditional and Nested fields :
Our advanced editor does not support Nested Fields
for example :
Textarea should include textfields,checkboxes,selects,radios, other text areas etc
This should also be reflected in the JSON schema as well