Reputation: 511
So far I have this function to call my search when enter is pressed:
$("#query").keypress(function(e) {
if(e.which == 13) {
alert('You pressed enter!');
redditsearch();
}
});
I'm getting the alert, but it gives me an error:
{"error": "Shell form does not validate{'html_initial_name':
u'initial-js_lib', 'form': <mooshell.forms.ShellForm object at
0x3787b50>, 'html_name': 'js_lib', 'html_initial_id': u'initial-id_js_lib',
'label': u'Js lib', 'field': <django.forms.models.ModelChoiceField object at 0x318ab50>,
'help_text': '', 'name': 'js_lib'}{'html_initial_name': u'initial-js_wrap',
'form': <mooshell.forms.ShellForm object at 0x3787b50>,
'html_name': 'js_wrap', 'html_initial_id': u'initial-id_js_wrap', 'label': u'Js wrap',
'field': <django.forms.fields.TypedChoiceField object at 0x270b510>, 'help_text': '',
'name': 'js_wrap'}"}
Upvotes: 0
Views: 210
Reputation: 2818
Try preventing the default behaviour of the enter keypress:
$("#query").keypress(function(e) {
if(e.which == 13) {
e.preventDefault();
alert('You pressed enter!');
redditsearch();
}
});
Without this, if your input is within a form, the form will be submitted along with your search function called. The preventDefault stops the default form submission behaviour.
Upvotes: 1