Error Validation
Hello, is there a way to implement custom error messages/validation for fields that are empty or expect a number, but string is passed for example? In the READ.me there is not mention, so just in case, wanted to ask here.
This is not supported at the moment. The JSON viewer itself supports passing a custom Editor for users who want to add new features or limitations on the input. See https://viewer.textea.io/how-to/data-types#editor
However, editor props do not contain path to retrieve path-specific validation rules.
https://github.com/TexteaInc/json-viewer/blob/0a1bcac5ff1e3b09a0556f0ddb5f650ecb2a6690/src/type.ts#L65-L70
Based on this, we can add path to the props to achieve what you want. Let me check the code later and get back to you, and possibly write an example/demo in the document. 🙏
Thank you for your response, will test this out :)
I will prepare a demo after #498 is merged.
Please check this demo with the input validation. I provided two implementations with different strategies. But this example is not perfect because the library does not provide a way to fully control the editing process. Users can still click the ✓ to submit changes.
I would suggest you use the commented way I left in the demo to disallow any invalid input.
Reopen since the library might need to have a way to do the checking before submitting the changes.
Would it be an idea to have some integration with JSON schemas?
@ianldgs I would expect it to be implemented in userland.
Yeah, just validation could make sense to do in user land. But facilitating editing, e.g. auto suggesting keys/values, could be a generic thing. Anyway, I had to move to Monaco editor for that, given I couldn't work out how to allow users to edit object keys.
Understandable. I would position this library as a JSON "viewer" with light editing abilities. Monaco would be more appropriate in some cases. 🙏