Skip to content

[Feature] Added handling of array of undefined validations #802

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

Merged
merged 3 commits into from
Jun 3, 2020

Conversation

Effanuel
Copy link
Contributor

@Effanuel Effanuel commented Jun 2, 2020

Issues:

  • Passing validate={[undefined, undefined]} throws red screen;

Motivation:

  • When having feature toggles and code that looks like this:
validate={[
   condition1 ? validateFunc1 : undefined,
   condition2 ? validateFunc2 : undefined
   ]}

The only solution is to use () => true, instead of undefined

Changes:

  • Added handling of array of undefined;

This only handles the situation where mutliple false returning values are the same

@ethanshar
Copy link
Collaborator

Hi @Effanuel
When I render

        <TextField
          placeholder="Placeholder"
          validate={[undefined, undefined]}
        />

I don't get any error.
Can you paste the code that throw an exception for u

@Effanuel
Copy link
Contributor Author

Effanuel commented Jun 3, 2020

Hi @Effanuel
When I render

        <TextField
          placeholder="Placeholder"
          validate={[undefined, undefined]}
        />

I don't get any error.
Can you paste the code that throw an exception for u

I have validateOnChange enabled, so when that triggers, I get an error.

You can basically see that in the code since [undefined, undefined] will evaluate to true and undefined to false.

@ethanshar
Copy link
Collaborator

Ok, cool it reproduce now.
Why not just add here a check for undefined here
https://github.com/wix/react-native-ui-lib/blob/master/src/components/inputs/BaseInput.js#L166

if (validatorFunction && !validatorFunction(value)) {

@ethanshar ethanshar merged commit ccee583 into master Jun 3, 2020
@Effanuel Effanuel deleted the HandleArrayOfUndefinedValidationFunctions branch June 3, 2020 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants