Comments (9)
Here's a simple example:
const MyForm = React.createClass({
getIntialState() {
return (
selected: [],
);
},
render() {
return (
<form>
<Typeahead
onChange={(selected) => this.setState({selected})}
options={this.props.options}
selected={this.state.selected}
/>
<button onClick={this.handleFormSubmission}>
Submit
</button>
</form>
);
},
handleFormSubmission() {
// When the user hits enter, do whatever form submission you need to do here.
// The typeahead's value is available in `this.state.selected`.
}
});
from react-bootstrap-typeahead.
Not sure I'm understanding correctly, but I think you're describing a case where the typeahead is part of a form, and some save action is called when the user clicks a "Save" button, or hits enter to submit the form, is that right?
from react-bootstrap-typeahead.
Yes, that's correct. How about something like this at the end of Typeahead.react.js _handleKeydown method:
if (!this.state.showMenu) { this.props.onKeyDown && this.props.onKeyDown(e) }
from react-bootstrap-typeahead.
The typeahead shouldn't need to be aware of if and when your form is submitted. Instead, it's the form's job to be aware of changes to the value of the typeahead (and any other input) and update the data it will send accordingly. Use the typeahead's onChange
prop to register changes in value.
from react-bootstrap-typeahead.
The onChange
prop only gives me the selected value, but I want to detect when the user hits 'Enter' after the input field has been filled in and then trigger the form submit/action. I can not detect user hitting 'Enter' without having an onKeyDown
hook.
from react-bootstrap-typeahead.
When you're talking about the user hitting "Enter," do you mean when the typeahead option is selected, or once the option is selected, an additional user action where the user submits the form?
from react-bootstrap-typeahead.
Once the option is selected and then an additional user action to submit the form.
from react-bootstrap-typeahead.
The typeahead's parent is the appropriate place to handle the "Enter" action, since it is aware of both the submission event as well as the typeahead's value.
from react-bootstrap-typeahead.
ahh, right, thank you, that will do the trick instead of trying to detect it myself in code.
from react-bootstrap-typeahead.
Related Issues (20)
- Max Results causes the results comes out-of-dated in the renderMenu HOT 2
- AsyncTypeAhead goes from uncontrolled to controlled HOT 4
- Wrong text is highlighted if Japanese diacritics present HOT 1
- onInputChange is not fired when an option is selected HOT 1
- return all the data properties inside the option of a particular option HOT 2
- Feature Request: Remove hardcoded style tag from hint HOT 1
- is there any way conditionally trigger MenuItem selection event? HOT 4
- Typeahead copy/paste value in field results in undefined when not selecting from list HOT 1
- Text overlay with suggested text when pasted from clipboard HOT 1
- Add button to end of list for "View All" elements, or any other action really HOT 1
- Scrolling gets "stuck", bound by keeping the active item in view HOT 1
- Uncaught Error: flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering HOT 3
- Options with a falsey "disabled" property get skipped on keyboard navigation HOT 1
- "Select All" prop HOT 4
- remove defaultProps from ClearButton HOT 1
- 6.3.0 defaults isLoading to true HOT 1
- Package failing in parcel bundler HOT 1
- Using Typeahead as Ref / createRef<Typeahead<any>>() / TS 5.2 / react 18.2.0 HOT 1
- Allow component in `labelKey` HOT 1
- There is no required attribute HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-bootstrap-typeahead.