简体   繁体   中英

Array of React-select in formik

i have an array of fields which has react select. so if i select an option in one index, then in next index, select, the option should not be visible. How can i achieve this functionality? I am calling the below function on OnBlur . if i delete the selected option it affects current selection too.So how to hide the option in next set of field

setTheatreList(values,setFieldTouched,index,options){
    setFieldTouched(`movie_screens_attributes[${index}].screen_id`,true)
    var i = options.findIndex(option => option.value == values.movie_screens_attributes[index].screen_id)
    debugger               
} 
 setScreenList(values,setFieldTouched,index,options){
    setFieldTouched(`movie_screens_attributes[${index}].screen_id`,true)
    if(index >= (this.state.previous_screens.length)){
        values.movie_screens_attributes.map(screen =>{
            if(this.state.previous_screens.includes(screen.screen_id)){

            }else{
                this.state.previous_screens.push(screen.screen_id)                    
            }
        })
    }
    else{
        const option = options.find(e => e.value == this.state.previous_screens[index])
        if(option){
            option.disabled = false
        }
        this.state.previous_screens[index]=values.movie_screens_attributes[index].screen_id    
    }

    if(options){
        var i = options.findIndex(option => option.value == values.movie_screens_attributes[index].screen_id)

        if(options[i]){

            options[i].disabled=true    
        }

        var flag = 0;
        for(i=0;i<options.length;i++){

            if(options[i].hasOwnProperty("disabled") && options[i]["disabled"]==true){

            }
            else{
                flag=-1
            }
        }
        if (flag ==0){
            var theatre_index =this.state.theatres.findIndex(option => option.value == values.movie_screens_attributes[index].theatre_id)
            if(this.state.theatres[theatre_index]){
                this.state.theatres[theatre_index].disabled=true
                debugger
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM