question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Autocomplete] onNewRequest to return an object

See original GitHub issue

Hi, I am using Material UI Components and they are really helpful. I am using an array of objects as datasource for Autocomplete. When I raises an ‘onNewRequest’ event than it passes the text value rather the object user selects. Can you plz see this.

My DataSource:

  var airportsList=[];
  this.airports.forEach(function(airport){

  airportsList.push({
    text: airport.itineraryAirportName[0],
    key:airport.id[0],
    value: <MenuItem
        primaryText={airport.itineraryAirportName[0]}
        secondaryText={airport.id[0]}
        style={{fontFamily:'caslon, garamond, serif !important'}}
        leftIcon={<span style={{border: '1px solid grey'}}
            className={countryClass}></span>}
        innerDivStyle={{paddingLeft: '50px'}}

        />
    })
  });

My Component:

 PickupAirportChange(t) {
     RAFActions.PickupAirportChange(t);
  },
 UpdateDropAirport(t) {
  var selectedAirport = '';
  if (t.length > 0) {
  for (var i = 0; i < this.props.airports.length; i++) {
    if (this.props.airports[i].itineraryAirportName[0] == t) {
      selectedAirport = this.props.airports[i];
      break;
      }

    }
  }
  <div className="col m11 l11 form-input departure-airport mt-15">
              <AutoComplete
                  hintText="Search Airport"
                  onUpdateInput= {this.PickupAirportChange}
                  onNewRequest={this.UpdatePickupAirport}
                  maxSearchResults={10}
                  dataSource={this.props.airportList}
                  filter={this.props.fil}
                  triggerUpdateOnFocus={true}
                  menuProps={{maxHeight:200,width:'100%'}}
                  underlineStyle={{display:'none'}}>
              </AutoComplete>
            </div>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
geoffreyabdallahcommented, Oct 4, 2016

I’m currently getting around this by Stringifying the object, passing that to text and then parsing to grab the fields I need in onNewRequest (hackey, but works for what I need right now). Example (don’t get too hung up on the Ramda stuff - general idea is to stringify the object, then parse when you need to use the object in onNewRequest):

//DataSource
const generateDataSource = mapIndexed((company, i) => ({
  text: JSON.stringify(company),
  value: (
    <ListItem
      key={i}
      primaryText={company.companyName}
    />
  ),
}));

// AutoComplete
<AutoComplete
  hintText="Company Name"
  floatingLabelText="Company Name"
  filter={R.identity}
  searchText={props.companyName}
  dataSource={generateDataSource(props.typeAheadCompanies)}
  onUpdateInput={props.updateCompanyName}
  onNewRequest={R.compose(props.selectExistingCompany, R.pick(['companyName', 'companyId']), JSON.parse)}
 />
0reactions
oliviertassinaricommented, Jul 20, 2017

Closed by #4783

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Autocomplete] onNewRequest to return an object · Issue #3789
Hi, I am using Material UI Components and they are really helpful. I am using an array of objects as datasource for Autocomplete....
Read more >
Developers - [Autocomplete] onNewRequest to return an object -
Hi, I am using Material UI Components and they are really helpful. I am using an array of objects as datasource for Autocomplete....
Read more >
How can we call onNewRequest property in onBlur in ...
Currently I am using Material-UI and I am using the onNewRequest property in AutoComplete field but the onNewRequest triggers only ...
Read more >
api documentation for material-ui (v0.17.1) - GitHub Pages
onNewRequest (); function material-ui.AutoComplete.defaultProps.onUpdateInput (); number material-ui.AutoComplete.defaultProps.menuCloseDelay; object ...
Read more >
Autocomplete API - Material UI - MUI
Name Type Default options * array renderInput * func autoComplete bool false
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found