Skip to content

Validation function doesn't work #1973

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

Closed
2 of 3 tasks
ywu151 opened this issue Aug 5, 2020 · 4 comments
Closed
2 of 3 tasks

Validation function doesn't work #1973

ywu151 opened this issue Aug 5, 2020 · 4 comments

Comments

@ywu151
Copy link

ywu151 commented Aug 5, 2020

Prerequisites

Description

I use basic function like
import Form from '@rjsf/core';
schema = {
properties: {
uuid: {
minLength: 10,
required: true,
type: 'string',
},
},
};
While the validation doesn't work and the submission is always triggered.
Here is a warning during submitting
Screen Shot 2020-08-05 at 3 45 24 PM

Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [and so on...]

Expected behavior

[What you expected to happen]

Actual behavior

[What actually happened]

Version

You can usually get this information in your package.json or in the file URL if you're using the unpkg one.

@epicfaace
Copy link
Member

Can you provide a full example of all your code (including using the actual

component)?

@ywu151
Copy link
Author

ywu151 commented Aug 6, 2020

Sure.
I use

"react": "^16.12.0",
"react-dom": "^16.12.0",
"styletron-react": "^5.2.6",
"bootstrap": "3.4.1",
"@rjsf/core": "^2.0.2",

for the code

import Form from '@rjsf/core';
import React, {useState} from 'react';
...
const [formData, setFormData] = useState({});
schema = {
    properties: {
      uuid: {
        minLength: 10,
        required: true,
        type: 'string',
      },
    },
  };
...
<div>
    <Helmet>
        <link
          href={assetUrl(
            '../../../node_modules/bootstrap/dist/css/bootstrap.min.css'
          )}
          rel="stylesheet"
        />
      </Helmet>
      <Form
        formData={formData}
        onChange={e => {setFormData(e.formData)}
        schema={schema}
      >
         <button />
      </Form>
</div>

Based on the Error information, it raised by ajv.validate(schema, formData); in node_modules/@rjsf/core/lib/validate.js
I also checked my ajv veriosn in yarn.lock

  ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.0, ajv@^6.5.5, ajv@^6.7.0:
  version "6.12.2"
  resolved "https://unpm.uberinternal.com/ajv/-/ajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd"
  integrity sha1-xinF7O0XuvMUQ3kY0tqIyZ1ZWM0=
  dependencies:
    fast-deep-equal "^3.1.1"
    fast-json-stable-stringify "^2.0.0"
    json-schema-traverse "^0.4.1"
    uri-js "^4.2.2"

@epicfaace
Copy link
Member

I think you have a typo. This line

onChange={e => {setFormData(e.formData)}

should be

onChange={e => setFormData(e.formData)}

Additionally, can you try removing the custom submit button and see if it works?

If the issue is still there, please make a custom jsfiddle (https://jsfiddle.net/n1k0/f2y3fq7L/6/) and share it with me.

@ywu151
Copy link
Author

ywu151 commented Aug 7, 2020

I fixed this error by adding

csp: {
    overrides: {scriptSrc: ["'unsafe-eval'"]},
},

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

No branches or pull requests

2 participants