Skip to content

Allow existing selected values#3

Open
preinvent wants to merge 4 commits intobharani91:masterfrom
preinvent:master
Open

Allow existing selected values#3
preinvent wants to merge 4 commits intobharani91:masterfrom
preinvent:master

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