What version of this package are you using?
v 3.22.1
What operating system, Node.js, and npm version?
- MacOS: Ventura 13.0.1 (22A400)
- node: v16.16.0
- npm: 8.11.0
What happened?
This is likely exactly the same issue as #455
REPRO STEPS (approx. 5 minutes or less):
npm create vite@latest my-vite-react-app -- --template react
cd my-vite-react-app
npm install
npm install validatorjs
- replace the contents of
src/App.jsx with the following:
import { useState } from 'react';
import './App.css';
import Validator from 'validatorjs';
const rules = { city: 'required', province: 'required' };
const goodData = { city: 'Toronto', province: 'Ontario' };
const badData = { city: undefined, province: 'Ontario' };
export const App = () => {
const [isValid, setIsValid] = useState();
const doValid = () => setIsValid(new Validator(goodData, rules).passes());
const doInvalid = () => setIsValid(new Validator(badData, rules).passes());
return (
<div className='App'>
<h2>Is valid: {isValid ? 'true' : 'false'} </h2>
<div>
<button onClick={doValid}> VALID </button>{' '}
<button onClick={doInvalid}> INVALID </button>
</div>
</div>
);
};
npm run dev
- in your browser, click the VALID button and see that "Is valid: true` displays
- click INVALID button and check the browser's JS console. You will see the same exception as reported initially.
What did you expect to happen?
EXPECTED: Both calls to Validator.passes() run without exceptions being thrown, and that the INVALID case returns an appropriate validation message.
ACTUAL: an exception is thrown in the INVALID case and no validation message is available.
Are you willing to submit a pull request to fix this bug?
Yes if someone suggests a valid solution.
What version of this package are you using?
v 3.22.1
What operating system, Node.js, and npm version?
What happened?
This is likely exactly the same issue as #455
REPRO STEPS (approx. 5 minutes or less):
npm create vite@latest my-vite-react-app -- --template reactcd my-vite-react-appnpm installnpm install validatorjssrc/App.jsxwith the following:npm run devWhat did you expect to happen?
EXPECTED: Both calls to Validator.passes() run without exceptions being thrown, and that the INVALID case returns an appropriate validation message.
ACTUAL: an exception is thrown in the INVALID case and no validation message is available.
Are you willing to submit a pull request to fix this bug?
Yes if someone suggests a valid solution.