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

How can we call onNewRequest property in onBlur in AutoComplete Material-UI field? #6708

Closed
Jayesh-nayak opened this issue Apr 26, 2017 · 2 comments
Labels
component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@Jayesh-nayak
Copy link

Jayesh-nayak commented Apr 26, 2017

Currently I am using Material-UI and I am using the onNewRequest property in AutoComplete field but the onNewRequest triggers only on Enter or when a value is selected, I wish to call the onNewRequest even when we click outside(i.e. onBlur property). Is this possible? I need to validate whether a user selects from the autocomplete options else throw an error but if the user enters any value and clicks outside the field he escapes the validation.

handleNewRequest = (content, index) => {
    if(index == -1){
     this.setState({errMsgMT : "Error"});
    }
    else{
     this.setState({errMsgMT : "Correct"});
    }
  };

  render() {
    return (
  <div>
        <AutoComplete
          hintText="Type 'r', case insensitive"
          onNewRequest={this.handleNewRequest}
          dataSource={colors}
        />
      </div>
    );
   }
 }
@audrium
Copy link

audrium commented May 9, 2017

I was able to achieve this by adding this line to Autocomplete field:
onBlur={(e) => this.handleNewRequest(e.target.value)}

@oliviertassinari
Copy link
Member

Closed by #4783

@oliviertassinari oliviertassinari added the component: autocomplete This is the name of the generic UI component, not the React module! label Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

3 participants