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

Validation on Null value "Is not of a type(s) string" #509

Closed
kentplaza opened this issue Mar 12, 2017 · 13 comments
Closed

Validation on Null value "Is not of a type(s) string" #509

kentplaza opened this issue Mar 12, 2017 · 13 comments

Comments

@kentplaza
Copy link

Description

Validation on type face problem when binding data from DB null.
The submit /post will not fire due to validation failed but if user simple enter some text and then erase it in the text box, the validation passed.

Way to produce

  1. Binding Null data in to text box

1

  1. Click on submit, error message will show.

2

  1. Type any text in text box and erase in by "backspace".
  2. Click on Submit. Post fired.
@n1k0
Copy link
Collaborator

n1k0 commented Mar 12, 2017

Indeed null is a specific jsonschema type and not a string. Try casting your null into undefined to mark the field unfilled.

@n1k0 n1k0 closed this as completed Mar 12, 2017
@kentplaza
Copy link
Author

kentplaza commented Mar 12, 2017

@n1k0 null is jasonschma type?

I try set "type": "null" as below but i got "Unsupported field schema { "type": "null"..."

"ID_NUMBER": {
"type": "null",
"title": "IC Number",
"pattern": "^$|^((\d{2}((0[13578]|1[02])(0[1-9]|[12]\d|3[01])|(0[13456789]|1[012])(0[1-9]|[12]\d|30)|02(0[1-9]|1\d|2[0-8])))|([02468][048]|[13579][26])0229)\d{2}\d{4}$",
"messages": {
pattern: "Invalid ic number format.",
}

@n1k0
Copy link
Collaborator

n1k0 commented Mar 12, 2017

The null jsonschema type only accepts null values (and supporting a null field wouldn't make any sense in a HTML forms library). You seem to be after a nullable string type, eg. ["string", "null"] (where a provided value could either be a string or null), but this isn't supported in this lib (see #282).

Still, turning your null DB values into js undefined ones should solve your initial use case here.

@1dolinski
Copy link

1dolinski commented May 16, 2017

Thoughts on a form option to cast nulls to undefined? For now I filter using the transformError prop - errors.filter(error => !!error.instance)

@amiuhle
Copy link

amiuhle commented May 23, 2017

I think there should be some supported solution for this, because null is a valid value if the field is not marked as required.

@n1k0
Copy link
Collaborator

n1k0 commented May 23, 2017

null is a valid value if the field is not marked as required.

If a field is not required, the object property should either be missing or set to the expected type:

@o-nix
Copy link

o-nix commented May 24, 2017

So, I'm doing a PATCH operation from all the field values. If I set nulls as undefined, I'm bypassing the validation but... I'm losing the fields for patching and the server thinks I'm just not sending any value for modification.

@n1k0
Copy link
Collaborator

n1k0 commented May 24, 2017

This is a client side form library. What you send to your server should probably be post-processed. Also, if your server expects null or string values for example, you should type your schema accordingly, with a composite schema type like ["null", "string"], though that is not supported by this lib yet.

But maybe someone wants to work on a patch?

@amiuhle
Copy link

amiuhle commented May 29, 2017

Derived from @1dolinski's comment, I'm currently filtering errors like this:

transformErrors={errors => errors.filter(error => error.hasOwnProperty('instance'))}

If I have some time left towards the end of the week, I'll look into creating a PR to support ["null", "string"].

@crankycookie
Copy link

crankycookie commented Jun 23, 2017

What was the outcome of this thread? Is the expectation to use

transformErrors={errors => errors.filter(error => error.hasOwnProperty('instance'))}

or is there support for ["null","string"] types?

@danhodkinson
Copy link

+1 for support for ["null","string"]

@atannerd
Copy link

+1 for support for ["null","string"]

@rjsf-team rjsf-team locked as resolved and limited conversation to collaborators Jan 5, 2018
@glasserc
Copy link
Contributor

glasserc commented Jan 5, 2018

["null", "string"] seems like a duplicate of #465.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants