rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
14.34k stars 2.19k forks source link

Can we set error from custom widget?? #697

Closed jariwalabhavesh closed 6 years ago

jariwalabhavesh commented 7 years ago

Prerequisites

Description

Can we set error from custom widget.??? Basically there is two way to manipulate and handle error:

  1. We can transform default error message to our own using transformErrors
  2. We can validate form data manually for custom validation requirement using validate

Example use case:

I am not getting any kind of error property or setError function that allow me to set error in form's error object in custom widget.

So is there any way to do it??

Thanks

j commented 7 years ago

Dang, I just left this same issue. Oops.

This feature should definitely be allowed.

glasserc commented 7 years ago

Hi, sorry @jariwalabhavesh for taking so long to answer. I thought about it and I guess I would be OK with having additional mechanisms to let developers write validation routines. However, the fact that both you and @j stumbled upon the exact same use case -- validating certain kinds of dates -- I also wonder if it would be simpler to just add better support for validating dates. For example, JSON Schema doesn't support minimum/maximum on dates, but maybe we could add some extensions that provide those fields when operating on date-time fields. Could you elaborate on what kinds of validations you need to perform on dates? I would be happy to review PRs that improve our support in this area.

jariwalabhavesh commented 7 years ago

Hi @glasserc , Very sorry for delay response. I am having validation like

To set error will be helpful to other widget as well when it is come's to custom widget. so user can validate data based on configuration passed to widget. For example: if i make custom widget to upload file, while uploading file if any error occur then i need to set error form widget.

glasserc commented 6 years ago

OK, this sounds like a duplicate of #155.

snirotem commented 3 years ago

Hi, i know its an old issue, but after spending couple of days without a hint, maybe here i will finally find an answer. How can raise an error from within a custom widget ?

i have a form with my custom widgets and also with customer-created widgets. some of those customer-created widgets may have custom validations, and i need to know how i should instruct them to raise validation errors.

M-S-Saurabh commented 3 years ago

Hi @snirotem, Did you figure out a way to raise error from within a custom widget? I am looking for solutions to the same problem.

epicfaace commented 3 years ago

I don't think it's currently possible. You may have to modify the validate function somehow instead.

Morriz commented 2 years ago

This is a big omission iyam, and should be put on the roadmap. Isn't it essential that a component governing user input can raise errors? And this is not a dupe of #155 as that pertains to jsonschema errors.

This should be re-opened as this is about custom widgets being able to raise errors (not all errors are schema based, i.e. when a widget is allowing schemaless yaml|json|whatever, but validates the input for correctness)

Morriz commented 2 years ago

/reopen

epicfaace commented 2 years ago

This should be re-opened as this is about custom widgets being able to raise errors (not all errors are schema based, i.e. when a widget is allowing schemaless yaml|json|whatever, but validates the input for correctness)

Can you please make a new issue? This issue is pretty old and hard to understand -- a new issue will make it easier to consolidate and understand what the problem is.

Morriz commented 2 years ago

Done: #2718