-
-
Notifications
You must be signed in to change notification settings - Fork 592
Customizable error messages #20
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
Comments
Hm. I'm inclined to believe that this deserves to be done at the application level. So, you'd presumably add any localization at that level, or if you had some other messages you wanted to display instead, or whatever. I think I'd need some more convincing to hear why the added complexity here is worthwhile :). |
Thanks for your response, Julian! If you're suggesting that user-facing validation happen at a completely different level -- in client-side JavaScript, for example -- I agree, and I am indeed doing that sort of thing in my Backbone.js models and forms. But if an invalid object is passed in for validation, perhaps because client-side validation was incomplete or outdated, I would rely on my JSON Schema validation to provide a useful error message that could be relayed back to the user. If I use I guess the basic question is whether error messages returned from the validation process are only for developers for review in a "this shouldn't happen" context (that is, your "user-level" validation failed you) or, as I'm suggesting, that the messages be suitable for inclusion into a user interface as-is. If your feeling is that these are developer messages, not user messages, I'll be happy to close the issue and thank you kindly for the code as it is! |
Reviewing the error objects returned by |
A ha! Cool, so we're getting somewhere :). In addition to the Given the I think we could benefit from including a helper function or two to help getting a property off the instance from a EDIT: So yeah, given your last message, to get the rest of the way, if what you're missing is the schema, I think that's going to be the dirty part. Because to implement that you'd need each validator to set a bunch of extra things on the error object, which are going to be validator-specific, and add a lot of code. I'm open to hear what you think would benefit you here though certainly. I think I'm open to adding a method to error objects that would do what you're asking if we can come up with a reasonable API for it. |
Hi. Hope you were successful. If not feel free to reopen. Cheers. |
Thanks, Julian - funny how this worked out. Our plan had changed to use XML instead of JSON, so jsonschema kind of dropped off my radar. But we just recently decided to return to JSON, so I'm back. Before I deal with the error messages, I've been trying to figure out if there's a way to define a reusable component -- say an "address" definition that needs to be used in multiple places -- within the same schema document. Thanks! |
I was considering a modification to allow replacing one or more of the validation error messages with alternatives -- perhaps phrased differently (to meet an application's style guidelines) or in different languages. The basic idea would be to have all of the places that generate error messages use a function that pulls the template from a dictionary in the Validator instance, and fall back to the "stock" messages if none is found. Would this be a welcome addition?
The text was updated successfully, but these errors were encountered: