FaridSafi / react-native-gifted-form

📝 « One React-Native form component to rule them all »
MIT License
1.44k stars 214 forks source link

SelectTypeaheadWidget #79

Open finnfiddle opened 8 years ago

finnfiddle commented 8 years ago

The library is great but I was in need of a select widget that could asynchronously fetch options from the server. So I made a component for it and tried to stick to the same coding style as much as I could. I've commented the propTypes as well as added an example of how it is used in the comments at the top of the file. Let me know if you don't agree with the way something has been done and I can update it.

Here is the usage example:

import React from 'react';
import { GiftedForm } from 'react-native-gifted-form';

const MyTypeaheadComponent = React.createClass({

  render() {
    return (
      <GiftedForm.SelectTypeaheadWidget
        title='Search'
        name='search'
        placeholder='Type to search...'
        noResultsText='Sorry, we couldnt find any results...'
        fetchOnMount={false}
        onSearch={this.handleSearch.bind(this)}
        onSearchError={error => { console.log(error); }}
      />
    )
  },

  handleSearch(text, callback) {
    // here you would do ajax call or something along those lines
    callback(null, [
      { id: 1, value: 1, label: 'Option 1' },
      { id: 2, value: 2, label: 'Option 2' },
      { id: 3, value: 3, label: 'Option 3' },
    ]);
  },

});
finnfiddle commented 7 years ago

any feedback on this?