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

'undefined' inputs throw a deprecation warning from Validator.js #104

Open
chronosis opened this issue Jan 17, 2018 · 1 comment
Open

'undefined' inputs throw a deprecation warning from Validator.js #104

chronosis opened this issue Jan 17, 2018 · 1 comment

Comments

@chronosis
Copy link

If an input from a React component is returned to Winterfell with an undefined value. A deprecation warning is thrown.

validator deprecated you tried to validate an undefined but this library (validator.js) validates strings only. Please update your code as this will be an error soon. node_modules/winterfell/dist/lib/validation.js:70:27

The simplest fix would be to coerce the value to an empty string in /src/lib/validation.js. So that lines 36 and 37 change from this:

var validateAnswer = (value, validationItem, questionAnswers) => {
  var validationMethod = typeof extraValidators[validationItem.type] !== 'undefined'
                           ? extraValidators[validationItem.type]
                           : Validator.hasOwnProperty(validationItem.type)
                               && typeof Validator[validationItem.type] === 'function'
                               ? Validator[validationItem.type]
                               : undefined;

To this:

var validateAnswer = (value, validationItem, questionAnswers) => {
  value = (value === undefined) ? '' : value;
  var validationMethod = typeof extraValidators[validationItem.type] !== 'undefined'
                           ? extraValidators[validationItem.type]
                           : Validator.hasOwnProperty(validationItem.type)
                               && typeof Validator[validationItem.type] === 'function'
                               ? Validator[validationItem.type]
                               : undefined;
@andrewhathaway
Copy link
Owner

Yeah for sure. This entire set of logic is awful and should be split out ideally. Also, it's ideal to not use the built in validator if you're validating against other types, when using selects etc.

Happy to accept a PR for this, from anyone, or will keep it open until it's something I can look at!

Thanks!

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

No branches or pull requests

2 participants