Submit Search Only On Enter Key? #2015
-
How can I disable instant search and submit only when ENTER key pressed? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
There exists an undocumented setting $('.ui.search')
.search({
automatic: false
})
; |
Beta Was this translation helpful? Give feedback.
-
I found workaround for the first issue, to re-submit anytime enter key pressed. $('.ui.search').on('keypress', function(e) {
if (e.keyCode == 13) { $('input').focus().select(); }
}); Now I only need to figureout how to check for empty input and close results box if its empty. Anyone? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Here is how my code looks and it works perfect. Thank you for unofficial setting "automatic: false". <div class="ui category search">
<div class="ui transparent icon input">
<input id="search" class="prompt" type="text" >
<i class="search link icon"></i>
</div>
<div class="results"></div>
</div> // fixes "backspace" key issue.
$('#search').on('keyup',function(){
if ($.trim($(this).val()).length == 0) {
$('#search').blur(); // hide results
$('#search').focus().select(); // focus input
}
});
// fixes "enter" (submit) key issue.
$('.ui.search').on('keyup', function(e) {
if (e.keyCode == 13) {
$('#search').focus().select();
}
});
// search javascript
$('.ui.search').search({
apiSettings: {
method: 'POST',
url: '/search?find={query}',
onAbort: function() { return false; },
onError: function() { return false; },
onFailure: function() { return false; }
},
fields: {
url: 'link',
title: 'name'
},
onSelect: function(e) {
window.location.href = e.link;
// fixes result box showing, after result selected.
// $('#search').blur(); // using "onAbort", "onError", "onFailure" instead.
},
maxResults: 10,
minCharacters: 5,
automatic: false
}); |
Beta Was this translation helpful? Give feedback.
Here is how my code looks and it works perfect. Thank you for unofficial setting "automatic: false".