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

Error Validation #476

Open
kozlovskk opened this issue Jun 7, 2024 · 5 comments · Fixed by #498
Open

Error Validation #476

kozlovskk opened this issue Jun 7, 2024 · 5 comments · Fixed by #498
Labels
enhancement New feature or request

Comments

@kozlovskk
Copy link

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.

@pionxzh
Copy link
Collaborator

pionxzh commented Jun 7, 2024

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.

json-viewer/src/type.ts

Lines 65 to 70 in 0a1bcac

export type EditorProps<ValueType = unknown> = {
value: ValueType
setValue: Dispatch<ValueType>
abortEditing: () => void
commitEditing: (newValue: string) => void
}

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

@pionxzh pionxzh added the enhancement New feature or request label Jun 7, 2024
@kozlovskk
Copy link
Author

Thank you for your response, will test this out :)

@pionxzh
Copy link
Collaborator

pionxzh commented Aug 13, 2024

I will prepare a demo after #498 is merged.

@pionxzh
Copy link
Collaborator

pionxzh commented Aug 27, 2024

Open in StackBlitz

image

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.

@pionxzh
Copy link
Collaborator

pionxzh commented Aug 27, 2024

Reopen since the library might need to have a way to do the checking before submitting the changes.

@pionxzh pionxzh reopened this Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants