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

On press does not change the text input #24

Closed
Talkwondo opened this issue Nov 6, 2016 · 5 comments
Closed

On press does not change the text input #24

Talkwondo opened this issue Nov 6, 2016 · 5 comments

Comments

@Talkwondo
Copy link

Hi,
After the autocomplete find the element, when I select it this does not show in the text input.
does anyone can understand what's happening?

<Autocomplete
data={notEatitems.length === 1 && comp(query, notEatitems[0]) ? [] : notEatitems}
defaultValue={query}
keyboardShouldPersistTaps={true}
onChangeText={text => this.setState({query: text})}
renderItem={data => (
<TouchableOpacity onPress={() =>
this.setState({query: data})}>
{data}

)}
/>

screen shot 2016-11-06 at 12 51 35

@vasiliy-sarzhynskyi
Copy link

vasiliy-sarzhynskyi commented Nov 6, 2016

hi,

I also have the same issue as @Talkwondo described above. I tried in iOS and Android devices and result is the same. I also tried different versions of react-native-autocomplete-input (2.0.0 and 1.1.2) and still see the issue. ReactNative version: 0.35.0.
It seems that renderItem does not work at all, because alert is never invoked in the following example (similar as in Example.js):

renderItem={({ title, release_date }) => (
                        <TouchableOpacity
                            onPress={() => {
                                alert('onPress!')
                                this.setState({ query: title })
                            }}>
                            <Text style={styles.itemText}>
                                {title} ({release_date.split('-')[0]})
                            </Text>
                        </TouchableOpacity>
                    )}

any ideas?

@mrlaessig
Copy link
Collaborator

Strange.. Does it work with the example?

@vasiliy-sarzhynskyi
Copy link

unfortunately your example does not work for me (tried on real Android device and on iOS simulator)

@vasiliy-sarzhynskyi
Copy link

vasiliy-sarzhynskyi commented Nov 20, 2016

hi @l-urence,
I finally found root of my problem: I put autocomplete component inside ScrollView (already checked solution for #5). So it works fine for Android and iOS with version 1.1.2.

As the title of issue: 'On press does not change the text input', I had the same behavior, but it could be solved by customizing component: use states for text input (defaultValue property) and key (autocompleteUpdateableKey: Math.random())

 <Autocomplete
                    // need this key for updating input field on selecting value from suggestion list
                    key={this.state.autocompleteUpdateableKey}
                    defaultValue={this.state.autocompleteDisplayedText}

@mrlaessig
Copy link
Collaborator

@vasiliy-sarzhynskyi cool then I will close this.

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

3 participants