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

When Item is selected in single select dropdown, it stores the selected item details but does not show in dropdown? #59

Open
prajna-h opened this issue Jan 6, 2021 · 10 comments

Comments

@prajna-h
Copy link

prajna-h commented Jan 6, 2021

`state = {
    visnames: [
        {
            id: 1,
            name: 'JavaScript',
        },
        {
            id: 2,
            name: 'Java',
        },
        {
            id: 3,
            name: 'Ruby',
        },
        {
            id: 4,
            name: 'React Native',
        },
        {
            id: 5,
            name: 'PHP',
        },
        {
            id: 6,
            name: 'Python',
        },
        {
            id: 7,
            name: 'Go',
        },
        {
            id: 8,
            name: 'Swift',
        },
    ],
    selectedStore: '',
    selectedStoreId: ''
};
<View style={{ margin: 20 }}>
    <SearchableDropdown
        onItemSelect={(item, index) => {
            console.log(item)
            this.setState({
                selectedStore: item.name,
                selectedStoreId: item.id
            })
        }}
        itemStyle={styles.dropdowninput}
        itemTextStyle={styles.searchdropdowncolor}
        itemsContainerStyle={styles.searchdropdown}
        items={visnames}
        defaultIndex={''}
        resetValue={false}
        textInputProps={
            {
                placeholder: "Select Store",
                underlineColorAndroid: "transparent",
                style: {
                    padding: 12,
                    borderWidth: 1,
                    borderColor: '#ccc',
                    borderRadius: 5,
                },
            }
        }
        listProps={{ nestedScrollEnabled: true, }}
    />
</View>`
@Cristiano1103
Copy link

Cristiano1103 commented Jan 18, 2021

Hello, i fix this problem doing this:

in this line: (/node_modules/react-native-searchable-dropdown)

{ key: 'value', val: this.state.item ? this.state.item.name : '' },

Change to:

{ key: 'value', val: this.state.item ? this.state.item.name : this.state.item },

i recommend u copy the file and pass to src/components to avoid update and reset your changes

@Munish-GitHub
Copy link

Munish-GitHub commented Jan 20, 2021

anyone found the solution. @Cristiano1103 I could not make it work either by that change.

@Cristiano1103
Copy link

@Munish-GitHub i changed , i`m using now UI Kitten, witch offers Select but without search. Works very good.

this solution is only for Apple, i tested in my android and didin't work. And have a lot of bugs. Try UI Kitten

@tanvirshajahan4
Copy link

My solution was to check if item i clicked use place holder to replace
eg:
placeholder ={this.state.carBrand=="" ?'Select Brand': this.state.carBrand}

@bhatvikrant
Copy link

@Munish-GitHub i changed , i`m using now UI Kitten, witch offers Select but without search. Works very good.

this solution is only for Apple, i tested in my android and didin't work. And have a lot of bugs. Try UI Kitten

Yea Autocomplete in UI Kitten has some positioning bugs for android

@bhatvikrant
Copy link

My solution was to check if item i clicked use place holder to replace
eg:
placeholder ={this.state.carBrand=="" ?'Select Brand': this.state.carBrand}

LOL what a work around buddy, works like a charm

@JagjeetSingh001
Copy link

JagjeetSingh001 commented May 10, 2021

I fixed the issue with commenting this line. because i console 'this.props.selectedItems' it returns undefined.

 return (
      <TextInput
        {...textInputProps}
        onBlur={(e) => {
          if (this.props.onBlur) {
            this.props.onBlur(e);
          }
          if (this.props.textInputProps && this.props.textInputProps.onBlur) {
            this.props.textInputProps.onBlur(e);
          }
          // this.setState({ focus: false, item: this.props.selectedItems }); // comment this line
        }
        }
      />

@abdullah-aj
Copy link

My solution was to check if item i clicked use place holder to replace
eg:
placeholder ={this.state.carBrand=="" ?'Select Brand': this.state.carBrand}

Saved my day

@booncoder123
Copy link

booncoder123 commented Oct 21, 2021

@Cristiano1103 his solution work for me nice! but it work only in IOS

@SamBaloyi
Copy link

My solution was to check if item i clicked use place holder to replace eg: placeholder ={this.state.carBrand=="" ?'Select Brand': this.state.carBrand}

This can even be made better by using the placeholderTextColor property for example

onItemSelect={(item) => setCarBrand(item.name)}
placeholder={car}
placeholderTextColor={car === "Default car value" ? color.palette.lightGrey : color.palette.black}

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

9 participants