
Hi,
I'm working on a module that uses some functionality provided by the AJAX module to AJAXify the search form on a D6 site. Some jQuery in my module adds a select list to search results that lists the different unique content types of the returned nodes; the goal is for it to run a new search when a user makes a selection from the list.
I've *almost* got it working - the select list shows up and populates correctly, and I've got it triggering a button-click on the search form's submit button when the user makes a selection.
But the redirect isn't right. It goes to a page that only has a JSON string on it. In that JSON string, I see a "redirect" value, and that value is correct - it's actually where I want the form to redirect to. So I think I'm close, and I think it's got something to do with things I'm (not) setting in the hook_form_alter that brings in the AJAX. Here's that function:
function results_filter_form_alter(&$form, $form_state, $form_id) {
switch($form_id) {
case 'search_form':
$form['#ajax'] = array(
'enabled' => TRUE
);
break;
}
}
The JSON that I see when jQuery re-submits the form looks like this:
{ "status": true, "updaters": [ ], "debug": [ ], "messages_error": [ ], "messages_status": [ ], "messages_warning": [ ], "redirect": "http://localhost/nano/search/node/nanoscale%20type%3Apage?712928367=1", "preview": null, "form_id": "search_form", "options": { "enabled": true } }
So, how can I get the form to redirect to the redirect value I see in the JSON?
Thanks!
UPDATE: I got it working! Turned out to be an issue with my JavaScript that was clicking the submit button. This is what was causing the problem:
$('#edit-submit').trigger('click');
When I changed it to this, it worked fine:
$('#search-form').submit();
I have no idea why this works, but hey, I'll take it.
Comments
I found that SUBMIT.mousedown
I found that SUBMIT.mousedown() worked. (Drupal & fully custom JScript only)
Both FORM.submit() and SUBMIT.trigger('click') failed.
Hope it helps.
Alan Davison
Thanks Alan!
Thanks Alan!
Seems that Ajax removes all click() handlers and mousedown() is a good workaround.