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

Allow existing selected values #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

preinvent
Copy link

In some cases the component may need to be populated with existing values. if we send in an array of label/value pairs to props.selectedOptions and initialize the state from that, we can easily support this.

@preinvent
Copy link
Author

Any eyes on this?

@mikeodell77
Copy link

Exactly what I needed for this to be a good solution for me

@ghalex
Copy link

ghalex commented Dec 20, 2016

I have extend the class to be able to add selectedValues:

class ExtendSelectPopover extends SelectPopover {
    constructor(props) {
        super(props);

        this.state = {
            focus: "out",
            searchTerm: "",
            selectedValues: this.props.selectedValues || []
        }
    }

    componentWillReceiveProps(nextProps) {
        if (nextProps.selectedValues) {
            this.setState({ selectedValues: nextProps.selectedValues });
        }
    }
}

@fiatjaf
Copy link

fiatjaf commented Dec 25, 2016

My fork: https://github.com/fiatjaf/react-select-popover, has support for this. It accepts a value prop that may be a simple array with the selected values referencing those in options (remember that options is an array of objects with the keys .value and .label). See prop types.

(I actually merged this same PR here, but ended up modifying the interface because I found some bugs and some inefficiencies).

(To install: npm install --save fiatjaf/react-select-popover)

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

Successfully merging this pull request may close these issues.

4 participants