Skip to content

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

@chronosis

Description

@chronosis

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;

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions