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

mixed.test function, this.options.originalValue, should i use it? #207

Closed
gabor opened this issue Apr 26, 2018 · 1 comment
Closed

mixed.test function, this.options.originalValue, should i use it? #207

gabor opened this issue Apr 26, 2018 · 1 comment

Comments

@gabor
Copy link

gabor commented Apr 26, 2018

i'm trying to validate a number-field, and to make sure it only contains a number (the default validator accepts things like "42haha". i did something like this:

const schema = yup.object().shape({
    num: yum.number().integer.required().test('foo', 'must-be-num', function(value) {
                    const orig = this.options.originalValue;
                    return value.toString() === orig.toString();
              }),
});

the question is, is the this.options.originalValue guaranteed to be there? i could not find anything about it in the documentation.

the this.options field only says:
the options object that validate() or isValid() was called with

validate says:

Options = {
  strict: boolean = false;
  abortEarly: boolean = true;
  stripUnknown: boolean = false;
  recursive: boolean = true;
  context: ?object;
}

so no info about the originalValue thing.

i'd just like to make sure i am using something i am supposed to use, and not some internal detail that can change with the next version.
alternatively, if there is a simpler way to achieve stricter number-validation, or a simpler way to get the originalValue in the test, please tell me.

@jquense jquense closed this as completed Jan 28, 2019
@shellscape
Copy link

@jquense why was this closed without a response? Ran into the same thing today and was searching the issues for an answer.

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

3 participants