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

allowCustomValues PropType requires Number but README says Boolean #246

Open
jacobsmith opened this issue Jan 26, 2018 · 1 comment
Open

Comments

@jacobsmith
Copy link

Hello,

Thanks for this library! It's been very easy to pull down and get integrated. I did run into one issue:

The current README states that allowCustomValues is a boolean prop that can be passed in ( https://github.com/fmoo/react-typeahead#propsallowcustomvalues ).

However, when I have that set to false, I see the following in my console:

Warning: Failed prop type: Invalid prop `allowCustomValues` of type `boolean` supplied to `Typeahead`, expected `number`.
    in Typeahead (created by Typeahead)
    in Typeahead (created by ConnectedField)
    in ConnectedField (created by Connect(ConnectedField))
    in Connect(ConnectedField) (created by Field)
    ...

I'd be more than happy to update documentation, but I wanted to check first what the intended use case is. My first impression was that if my list contains ['foo', 'bar'] and I type fooa and click away, the onBlur would set it back to empty (because I want to disallow entries that are not in the list). I'm not seeing that behavior, so figured I can write up some documentation with the results of this thread.

Thanks!

@jacobsmith
Copy link
Author

Due to some other business requirements, I ended up using https://github.com/reactjs/react-autocomplete instead. To achieve the same requirement of users selecting from the list, I implemented a validation of:

Typeahead.validateSelectedIsOneOf = (items, display) => {
  return function(value) {
    if (items.map((item) => display(item)).indexOf(value) < 0) {
      return 'Please select from the list';
    }

    // ReduxForm expects "undefined" explicitly if no error is to be raised
    return undefined; // eslint-disable-line no-undefined
  };
};

It may or may not be useful to any future person who finds this issue.

I will leave the issue open as it still seems like either the documentation or the code is slightly mismatched, but feel free to close it if any maintainer sees fit.

Thanks!

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

1 participant