In our implementation of JsonForms we have built a drag and drop interface which our users can use to build forms that will be filled out by their customers. To explain the app in a simplistic way, we have built a user interface for generating schema to render forms using this library.
We are looking to allow users to create their own validations on a field by field basis.
For example if a user adds an input field into their form and labels it Membership Account ID
. We want to allow them to attach a custom validation rule to this field. The validation rule needs to show a custom error message when it is not met. An example of the types of random validations that would be made are: the first four characters must be ACBD
, followed by seven numbers, followed by one character, and must end in a -0
. These types of validation rules are completely unknown to us before they are created. We are hoping to do this with a Regex rule and error message structure like follows. So the user would be putting in their own regex string and error message when this regex does not meet the value returned by the control.
As far as I can tell by reading previous posts and questions there are two approaches to this. The first would be to create a new type
for any field they create a validation for. Then we would inject the new rules for each type into JsonForms using AJV. In the example above the schema type for their input field would be something like type: membership-account-id
or something. This seems like a straight forward approach and has the benefit of using the pre-packed validation. It seems to not play well with testers though. We would need to build in some backdoor with very high rank that determines the renderer that is chosen regardless of type.
The second approach appears to create a custom validation layer ourselves. This seems to be a nicer approach for testers but I have a few questions. In this scenario do we store our errors within the JsonForms state or manage it externally? Is there a HOC outside of the basic ones that injects some sort of addErrors
function that we can use to inject a way to manually add errors inside our custom renderers? Is there any built in handling for things like clearing errors in this scenario? Or is it completely custom endeavor.
All in all any recommendations or sources of more information would be helpful to guide us in a decision. Is there any sort of middle ground here? Can we change what key AJV uses in the schema to determine the validator that is ran instead of type? Thanks in advance.