How to search only when clicked enter, not as typed #2296
Unanswered
furkanayilmaz
asked this question in
Q&A
Replies: 1 comment 1 reply
-
There is an |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Everyone,
I have my DataSearch and I want to make it so that it searches when I hit enter. I already have onKeyDown code but yet still it searches as I type but the behavior should be to wait and not query and only query when clicked enter. Any help appreciated. Thank you!
`constructor(props) {
super(props);
this.state = {
value: '',
};
}
render = () => {
const { className, ...props } = this.props;
return (
<StyledDataSearch
componentId={REACTIVE_ID}
filterLabel="Search"
onKeyDown={(event: React.KeyboardEvent, triggerQuery: () => void) => {
if (event.key === 'Enter') {
triggerQuery();
}
}}
value={this.state.value}
onChange={(value) => this.setState({ value })}
customQuery={props.customQuery || ((value, props) => {
const escaped = value
.replace('/', '\/')
.replace(/[^0-9a-zA-Z._\\/]/g, ' ')
.toLowerCase()
if (!value) {
return {};
}
return {
query: {
query_string: {
query: escaped,
fields: props.dataField,
default_operator: props.queryFormat,
},
},
};
})}
{...props}
/>
);
};`
Beta Was this translation helpful? Give feedback.
All reactions