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

Different filter options #23

Closed
EricTill opened this issue Dec 3, 2014 · 2 comments
Closed

Different filter options #23

EricTill opened this issue Dec 3, 2014 · 2 comments

Comments

@EricTill
Copy link

EricTill commented Dec 3, 2014

From what I can see in the code here:

filterOptions: function(options, values) {
    var filterValue = this._optionsFilterString;
    var exclude = (values || this.state.values).map(function(i) {
        return i.value;
    });
    var filterOption = function(op) {
        if (this.props.multi && _.contains(exclude, op.value)) return false;
        return (
            !filterValue
            || op.value.toLowerCase().indexOf(filterValue.toLowerCase()) >= 0
            || op.label.toLowerCase().indexOf(filterValue.toLowerCase()) >= 0
        );
    }
    return _.filter(options, filterOption, this);
},

(Lines 318-332 currently)

There's no way to edit how the filtering is done, but I'd like to restrict the results to options whose values start with the current value of the text box. I realize I can very easily edit this section of the code to do that, but it would be cool if this option came from a prop (like match={both/start} or something like that). https://github.com/rackt/react-autocomplete has that option and it's been pretty useful.

@JedWatson
Copy link
Owner

Done! This is now live with v0.2.8

I've also added an option to control whether the label or the value are checked. Both options default to any which I thought was clear than both.

<Select ... filterPos="start" filterProp="value" />

@EricTill
Copy link
Author

EricTill commented Dec 8, 2014

Good stuff! Thanks, man.

CoreyTrombley pushed a commit to Unified/react-select that referenced this issue Jan 5, 2015
Methuselah96 added a commit to Methuselah96/react-select that referenced this issue Nov 22, 2020
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

2 participants