Multiple unique dropdown security questions in REACT.js












1















I am trying to generate a series of security questions. I have a pool of available questions. There will be three such question dropdown list in my webpage. Q1,Q2,Q3.
I am able to build that quite correctly. Using react select.



However, the problem is when I am selecting one question in Q1. I want that question not to be available in the dropdown for Q2. However everytime it appears the same set. Howcan I remove the already selected questions from the list.?



             class dropdownqs extends React.Component {
constructor() {
super();
this.state = {
options : [
{ value: ‘What was your childhood nickname?’, label: ‘What was your childhood nickname?’ },
{ value: ‘In what city did you meet your spouse/significant other?’, label: ‘In what city did you meet your spouse/significant other?’},
{ value: ‘What is the name of your favorite childhood friend?’, label: ‘What is the name of your favorite childhood friend?’},
{ value: ‘What street did you live on in third grade?’, label: ‘What street did you live on in third grade?’},
{ value: ‘What is the middle name of your youngest child?’, label: ‘What is the middle name of your youngest child?’ },
{ value: ‘What is the middle name of your oldest sibling?’, label: ‘What is the middle name of your oldest sibling?’},
{ value: ‘What school did you attend for sixth grade?’, label: ‘What school did you attend for sixth grade’ },
{ value: ‘What was the name of your first stuffed animal?’, label: ‘What was the name of your first stuffed animal?’ },
{ value: ‘In what city or town did your mather and father meet?’, label: ‘In what city or town did your mather and father meet?’ }
]
}
this.handleChangeqs1 = this.handleChangeqs1.bind(this);
this.handleChangeqs2 = this.handleChangeqs2.bind(this);
this.handleChangeqs3 = this.handleChangeqs3.bind(this);


// function
handleChangeqs1(selectedOption){
// this.setState({ selectedOption});
this.setState({ selectedOptionqs1: selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
// function
handleChangeqs2(selectedOption) {
//this.setState({ selectedOption});
this.setState({ selectedOptionqs2:selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
// function
handleChangeqs3(selectedOption) {
//this.setState({ selectedOption});
this.setState({ selectedOptionqs3 : selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
render() {
const { selectedOption } = this.state;
return (
<div className=“App”>
{/* BODY */}
<body className=“App-body-register”>



{/* SECURITY QUESTIONS */}
<div align=“left”>
{/* 1st Security Question */}
<h3>
Security question 1
</h3>
{/* //select question */}
<Select
id=“Question1select”
editable={false}
value={selectedOption}
onChange={this.handleChangeqs1.bind(this)}
options={this.state.options}
/>

{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security1ans” minlength=“4" maxlength=“20”
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>


{/* // 2nd Security Question */}
<h3>
Security question 2
</h3>
{/* //select question */}
<Select
value={selectedOption}
onChange={this.handleChangeqs2.bind(this)}
options={this.state.options}
/>
{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security2ans” minlength=“4” maxlength=“20"
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>

{/* // 3rd Security Question */}
<h3>
Security question 3
</h3>
{/* //select question */}
<Select
value={selectedOption}
onChange={this.handleChangeqs3.bind(this)}
options={this.state.options}
/>
{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security3ans” minlength=“4" maxlength=“20”
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>
</div>
</body>
</div>
);
}
export default dropdownqs;


I was following the code in https://github.com/JedWatson/react-select










share|improve this question

























  • Can you show us your attempted implementation of the component using <Select>?

    – Shawn Andrews
    Nov 28 '18 at 0:43











  • <Select id=“Question1select” editable={false} value={selectedOption} onChange={this.handleChangeqs1.bind(this)} options={this.state.options} />

    – Avishek Banerjee
    Nov 28 '18 at 0:48













  • Can you edit the original post to include the full code of the component using Select?

    – Shawn Andrews
    Nov 28 '18 at 0:48











  • Done @ShawnAndrews

    – Avishek Banerjee
    Nov 28 '18 at 1:06
















1















I am trying to generate a series of security questions. I have a pool of available questions. There will be three such question dropdown list in my webpage. Q1,Q2,Q3.
I am able to build that quite correctly. Using react select.



However, the problem is when I am selecting one question in Q1. I want that question not to be available in the dropdown for Q2. However everytime it appears the same set. Howcan I remove the already selected questions from the list.?



             class dropdownqs extends React.Component {
constructor() {
super();
this.state = {
options : [
{ value: ‘What was your childhood nickname?’, label: ‘What was your childhood nickname?’ },
{ value: ‘In what city did you meet your spouse/significant other?’, label: ‘In what city did you meet your spouse/significant other?’},
{ value: ‘What is the name of your favorite childhood friend?’, label: ‘What is the name of your favorite childhood friend?’},
{ value: ‘What street did you live on in third grade?’, label: ‘What street did you live on in third grade?’},
{ value: ‘What is the middle name of your youngest child?’, label: ‘What is the middle name of your youngest child?’ },
{ value: ‘What is the middle name of your oldest sibling?’, label: ‘What is the middle name of your oldest sibling?’},
{ value: ‘What school did you attend for sixth grade?’, label: ‘What school did you attend for sixth grade’ },
{ value: ‘What was the name of your first stuffed animal?’, label: ‘What was the name of your first stuffed animal?’ },
{ value: ‘In what city or town did your mather and father meet?’, label: ‘In what city or town did your mather and father meet?’ }
]
}
this.handleChangeqs1 = this.handleChangeqs1.bind(this);
this.handleChangeqs2 = this.handleChangeqs2.bind(this);
this.handleChangeqs3 = this.handleChangeqs3.bind(this);


// function
handleChangeqs1(selectedOption){
// this.setState({ selectedOption});
this.setState({ selectedOptionqs1: selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
// function
handleChangeqs2(selectedOption) {
//this.setState({ selectedOption});
this.setState({ selectedOptionqs2:selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
// function
handleChangeqs3(selectedOption) {
//this.setState({ selectedOption});
this.setState({ selectedOptionqs3 : selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
render() {
const { selectedOption } = this.state;
return (
<div className=“App”>
{/* BODY */}
<body className=“App-body-register”>



{/* SECURITY QUESTIONS */}
<div align=“left”>
{/* 1st Security Question */}
<h3>
Security question 1
</h3>
{/* //select question */}
<Select
id=“Question1select”
editable={false}
value={selectedOption}
onChange={this.handleChangeqs1.bind(this)}
options={this.state.options}
/>

{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security1ans” minlength=“4" maxlength=“20”
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>


{/* // 2nd Security Question */}
<h3>
Security question 2
</h3>
{/* //select question */}
<Select
value={selectedOption}
onChange={this.handleChangeqs2.bind(this)}
options={this.state.options}
/>
{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security2ans” minlength=“4” maxlength=“20"
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>

{/* // 3rd Security Question */}
<h3>
Security question 3
</h3>
{/* //select question */}
<Select
value={selectedOption}
onChange={this.handleChangeqs3.bind(this)}
options={this.state.options}
/>
{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security3ans” minlength=“4" maxlength=“20”
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>
</div>
</body>
</div>
);
}
export default dropdownqs;


I was following the code in https://github.com/JedWatson/react-select










share|improve this question

























  • Can you show us your attempted implementation of the component using <Select>?

    – Shawn Andrews
    Nov 28 '18 at 0:43











  • <Select id=“Question1select” editable={false} value={selectedOption} onChange={this.handleChangeqs1.bind(this)} options={this.state.options} />

    – Avishek Banerjee
    Nov 28 '18 at 0:48













  • Can you edit the original post to include the full code of the component using Select?

    – Shawn Andrews
    Nov 28 '18 at 0:48











  • Done @ShawnAndrews

    – Avishek Banerjee
    Nov 28 '18 at 1:06














1












1








1








I am trying to generate a series of security questions. I have a pool of available questions. There will be three such question dropdown list in my webpage. Q1,Q2,Q3.
I am able to build that quite correctly. Using react select.



However, the problem is when I am selecting one question in Q1. I want that question not to be available in the dropdown for Q2. However everytime it appears the same set. Howcan I remove the already selected questions from the list.?



             class dropdownqs extends React.Component {
constructor() {
super();
this.state = {
options : [
{ value: ‘What was your childhood nickname?’, label: ‘What was your childhood nickname?’ },
{ value: ‘In what city did you meet your spouse/significant other?’, label: ‘In what city did you meet your spouse/significant other?’},
{ value: ‘What is the name of your favorite childhood friend?’, label: ‘What is the name of your favorite childhood friend?’},
{ value: ‘What street did you live on in third grade?’, label: ‘What street did you live on in third grade?’},
{ value: ‘What is the middle name of your youngest child?’, label: ‘What is the middle name of your youngest child?’ },
{ value: ‘What is the middle name of your oldest sibling?’, label: ‘What is the middle name of your oldest sibling?’},
{ value: ‘What school did you attend for sixth grade?’, label: ‘What school did you attend for sixth grade’ },
{ value: ‘What was the name of your first stuffed animal?’, label: ‘What was the name of your first stuffed animal?’ },
{ value: ‘In what city or town did your mather and father meet?’, label: ‘In what city or town did your mather and father meet?’ }
]
}
this.handleChangeqs1 = this.handleChangeqs1.bind(this);
this.handleChangeqs2 = this.handleChangeqs2.bind(this);
this.handleChangeqs3 = this.handleChangeqs3.bind(this);


// function
handleChangeqs1(selectedOption){
// this.setState({ selectedOption});
this.setState({ selectedOptionqs1: selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
// function
handleChangeqs2(selectedOption) {
//this.setState({ selectedOption});
this.setState({ selectedOptionqs2:selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
// function
handleChangeqs3(selectedOption) {
//this.setState({ selectedOption});
this.setState({ selectedOptionqs3 : selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
render() {
const { selectedOption } = this.state;
return (
<div className=“App”>
{/* BODY */}
<body className=“App-body-register”>



{/* SECURITY QUESTIONS */}
<div align=“left”>
{/* 1st Security Question */}
<h3>
Security question 1
</h3>
{/* //select question */}
<Select
id=“Question1select”
editable={false}
value={selectedOption}
onChange={this.handleChangeqs1.bind(this)}
options={this.state.options}
/>

{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security1ans” minlength=“4" maxlength=“20”
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>


{/* // 2nd Security Question */}
<h3>
Security question 2
</h3>
{/* //select question */}
<Select
value={selectedOption}
onChange={this.handleChangeqs2.bind(this)}
options={this.state.options}
/>
{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security2ans” minlength=“4” maxlength=“20"
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>

{/* // 3rd Security Question */}
<h3>
Security question 3
</h3>
{/* //select question */}
<Select
value={selectedOption}
onChange={this.handleChangeqs3.bind(this)}
options={this.state.options}
/>
{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security3ans” minlength=“4" maxlength=“20”
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>
</div>
</body>
</div>
);
}
export default dropdownqs;


I was following the code in https://github.com/JedWatson/react-select










share|improve this question
















I am trying to generate a series of security questions. I have a pool of available questions. There will be three such question dropdown list in my webpage. Q1,Q2,Q3.
I am able to build that quite correctly. Using react select.



However, the problem is when I am selecting one question in Q1. I want that question not to be available in the dropdown for Q2. However everytime it appears the same set. Howcan I remove the already selected questions from the list.?



             class dropdownqs extends React.Component {
constructor() {
super();
this.state = {
options : [
{ value: ‘What was your childhood nickname?’, label: ‘What was your childhood nickname?’ },
{ value: ‘In what city did you meet your spouse/significant other?’, label: ‘In what city did you meet your spouse/significant other?’},
{ value: ‘What is the name of your favorite childhood friend?’, label: ‘What is the name of your favorite childhood friend?’},
{ value: ‘What street did you live on in third grade?’, label: ‘What street did you live on in third grade?’},
{ value: ‘What is the middle name of your youngest child?’, label: ‘What is the middle name of your youngest child?’ },
{ value: ‘What is the middle name of your oldest sibling?’, label: ‘What is the middle name of your oldest sibling?’},
{ value: ‘What school did you attend for sixth grade?’, label: ‘What school did you attend for sixth grade’ },
{ value: ‘What was the name of your first stuffed animal?’, label: ‘What was the name of your first stuffed animal?’ },
{ value: ‘In what city or town did your mather and father meet?’, label: ‘In what city or town did your mather and father meet?’ }
]
}
this.handleChangeqs1 = this.handleChangeqs1.bind(this);
this.handleChangeqs2 = this.handleChangeqs2.bind(this);
this.handleChangeqs3 = this.handleChangeqs3.bind(this);


// function
handleChangeqs1(selectedOption){
// this.setState({ selectedOption});
this.setState({ selectedOptionqs1: selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
// function
handleChangeqs2(selectedOption) {
//this.setState({ selectedOption});
this.setState({ selectedOptionqs2:selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
// function
handleChangeqs3(selectedOption) {
//this.setState({ selectedOption});
this.setState({ selectedOptionqs3 : selectedOption });
var i;
var array = this.state.options;
for(i = 0; i < array.length; i++){
if(array[i].value==selectedOption.value){
array.splice(i,1)
this.setState({
options: array
})
break;
}
}
}
render() {
const { selectedOption } = this.state;
return (
<div className=“App”>
{/* BODY */}
<body className=“App-body-register”>



{/* SECURITY QUESTIONS */}
<div align=“left”>
{/* 1st Security Question */}
<h3>
Security question 1
</h3>
{/* //select question */}
<Select
id=“Question1select”
editable={false}
value={selectedOption}
onChange={this.handleChangeqs1.bind(this)}
options={this.state.options}
/>

{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security1ans” minlength=“4" maxlength=“20”
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>


{/* // 2nd Security Question */}
<h3>
Security question 2
</h3>
{/* //select question */}
<Select
value={selectedOption}
onChange={this.handleChangeqs2.bind(this)}
options={this.state.options}
/>
{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security2ans” minlength=“4” maxlength=“20"
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>

{/* // 3rd Security Question */}
<h3>
Security question 3
</h3>
{/* //select question */}
<Select
value={selectedOption}
onChange={this.handleChangeqs3.bind(this)}
options={this.state.options}
/>
{/* //input answer */}
<input type=“text” className=“App-login-input” id=“security3ans” minlength=“4" maxlength=“20”
placeholder=“Must be a minimum of 4 characters long” required/>
<span class=“validity”></span>
</div>
</body>
</div>
);
}
export default dropdownqs;


I was following the code in https://github.com/JedWatson/react-select







reactjs react-select






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 1:04







Avishek Banerjee

















asked Nov 28 '18 at 0:38









Avishek BanerjeeAvishek Banerjee

163




163













  • Can you show us your attempted implementation of the component using <Select>?

    – Shawn Andrews
    Nov 28 '18 at 0:43











  • <Select id=“Question1select” editable={false} value={selectedOption} onChange={this.handleChangeqs1.bind(this)} options={this.state.options} />

    – Avishek Banerjee
    Nov 28 '18 at 0:48













  • Can you edit the original post to include the full code of the component using Select?

    – Shawn Andrews
    Nov 28 '18 at 0:48











  • Done @ShawnAndrews

    – Avishek Banerjee
    Nov 28 '18 at 1:06



















  • Can you show us your attempted implementation of the component using <Select>?

    – Shawn Andrews
    Nov 28 '18 at 0:43











  • <Select id=“Question1select” editable={false} value={selectedOption} onChange={this.handleChangeqs1.bind(this)} options={this.state.options} />

    – Avishek Banerjee
    Nov 28 '18 at 0:48













  • Can you edit the original post to include the full code of the component using Select?

    – Shawn Andrews
    Nov 28 '18 at 0:48











  • Done @ShawnAndrews

    – Avishek Banerjee
    Nov 28 '18 at 1:06

















Can you show us your attempted implementation of the component using <Select>?

– Shawn Andrews
Nov 28 '18 at 0:43





Can you show us your attempted implementation of the component using <Select>?

– Shawn Andrews
Nov 28 '18 at 0:43













<Select id=“Question1select” editable={false} value={selectedOption} onChange={this.handleChangeqs1.bind(this)} options={this.state.options} />

– Avishek Banerjee
Nov 28 '18 at 0:48







<Select id=“Question1select” editable={false} value={selectedOption} onChange={this.handleChangeqs1.bind(this)} options={this.state.options} />

– Avishek Banerjee
Nov 28 '18 at 0:48















Can you edit the original post to include the full code of the component using Select?

– Shawn Andrews
Nov 28 '18 at 0:48





Can you edit the original post to include the full code of the component using Select?

– Shawn Andrews
Nov 28 '18 at 0:48













Done @ShawnAndrews

– Avishek Banerjee
Nov 28 '18 at 1:06





Done @ShawnAndrews

– Avishek Banerjee
Nov 28 '18 at 1:06












1 Answer
1






active

oldest

votes


















1














To have 3 input select's where each cannot select an option chosen by the rest of the select's you'll want to start by adding a new property to your existing state that holds all the already chosen questions.



Once we know the options already chosen by all select's we can begin with all possible questions then filter out those questions already chosen via the filter function:



getAvailableOptions = () => {
const availableOptionsLeft = this.state.filterOptions;
return availableOptionsLeft.filter(questionOption => {
return this.state.questionVals.indexOf(questionOption) === -1;
});
};


Demonstration: https://codesandbox.io/s/yvv3y14x09






share|improve this answer
























  • Thanks a lot. Was stuck on this issue for 2 hours.

    – Avishek Banerjee
    Nov 28 '18 at 2:15






  • 1





    No worries:) Dont forget to mark it as Answered so others know it will work for them

    – Shawn Andrews
    Nov 28 '18 at 3:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53510400%2fmultiple-unique-dropdown-security-questions-in-react-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














To have 3 input select's where each cannot select an option chosen by the rest of the select's you'll want to start by adding a new property to your existing state that holds all the already chosen questions.



Once we know the options already chosen by all select's we can begin with all possible questions then filter out those questions already chosen via the filter function:



getAvailableOptions = () => {
const availableOptionsLeft = this.state.filterOptions;
return availableOptionsLeft.filter(questionOption => {
return this.state.questionVals.indexOf(questionOption) === -1;
});
};


Demonstration: https://codesandbox.io/s/yvv3y14x09






share|improve this answer
























  • Thanks a lot. Was stuck on this issue for 2 hours.

    – Avishek Banerjee
    Nov 28 '18 at 2:15






  • 1





    No worries:) Dont forget to mark it as Answered so others know it will work for them

    – Shawn Andrews
    Nov 28 '18 at 3:23
















1














To have 3 input select's where each cannot select an option chosen by the rest of the select's you'll want to start by adding a new property to your existing state that holds all the already chosen questions.



Once we know the options already chosen by all select's we can begin with all possible questions then filter out those questions already chosen via the filter function:



getAvailableOptions = () => {
const availableOptionsLeft = this.state.filterOptions;
return availableOptionsLeft.filter(questionOption => {
return this.state.questionVals.indexOf(questionOption) === -1;
});
};


Demonstration: https://codesandbox.io/s/yvv3y14x09






share|improve this answer
























  • Thanks a lot. Was stuck on this issue for 2 hours.

    – Avishek Banerjee
    Nov 28 '18 at 2:15






  • 1





    No worries:) Dont forget to mark it as Answered so others know it will work for them

    – Shawn Andrews
    Nov 28 '18 at 3:23














1












1








1







To have 3 input select's where each cannot select an option chosen by the rest of the select's you'll want to start by adding a new property to your existing state that holds all the already chosen questions.



Once we know the options already chosen by all select's we can begin with all possible questions then filter out those questions already chosen via the filter function:



getAvailableOptions = () => {
const availableOptionsLeft = this.state.filterOptions;
return availableOptionsLeft.filter(questionOption => {
return this.state.questionVals.indexOf(questionOption) === -1;
});
};


Demonstration: https://codesandbox.io/s/yvv3y14x09






share|improve this answer













To have 3 input select's where each cannot select an option chosen by the rest of the select's you'll want to start by adding a new property to your existing state that holds all the already chosen questions.



Once we know the options already chosen by all select's we can begin with all possible questions then filter out those questions already chosen via the filter function:



getAvailableOptions = () => {
const availableOptionsLeft = this.state.filterOptions;
return availableOptionsLeft.filter(questionOption => {
return this.state.questionVals.indexOf(questionOption) === -1;
});
};


Demonstration: https://codesandbox.io/s/yvv3y14x09







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 28 '18 at 1:42









Shawn AndrewsShawn Andrews

965618




965618













  • Thanks a lot. Was stuck on this issue for 2 hours.

    – Avishek Banerjee
    Nov 28 '18 at 2:15






  • 1





    No worries:) Dont forget to mark it as Answered so others know it will work for them

    – Shawn Andrews
    Nov 28 '18 at 3:23



















  • Thanks a lot. Was stuck on this issue for 2 hours.

    – Avishek Banerjee
    Nov 28 '18 at 2:15






  • 1





    No worries:) Dont forget to mark it as Answered so others know it will work for them

    – Shawn Andrews
    Nov 28 '18 at 3:23

















Thanks a lot. Was stuck on this issue for 2 hours.

– Avishek Banerjee
Nov 28 '18 at 2:15





Thanks a lot. Was stuck on this issue for 2 hours.

– Avishek Banerjee
Nov 28 '18 at 2:15




1




1





No worries:) Dont forget to mark it as Answered so others know it will work for them

– Shawn Andrews
Nov 28 '18 at 3:23





No worries:) Dont forget to mark it as Answered so others know it will work for them

– Shawn Andrews
Nov 28 '18 at 3:23




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53510400%2fmultiple-unique-dropdown-security-questions-in-react-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks