I've got a block view which is using ajax to display an exposed date filter. The filter works great, searching and displaying the proper records -- but what I'm after is to get the value of the submission to have it display in a nice little calendar icon (see link below).
I'm using a custom hook_form_alter module to rearrange the order of the date parts in my form so I've been trying various ways to grab the values. Specifically, I did a simple if(!(empty($_GET["v"]))), where "v" is my filter identifier -- but all this did was cause the spinner to rotate endlessly and not display any results.
Thanks for any suggestions anyone can offer!
Screenshot: http://www.tentenstudios.com/clients/zoo/zoo_form.png
Here's my custom module, at the moment:
<?php
function filteroverride_form_alter(&$form, &$form_state, $form_id) {
if($form['#id'] == 'views-exposed-form-today-block-1') {
$form['v']['value']['#date_format'] = 'F-d-Y';
//if(!(empty($_GET["v"]))) {
//print '<p>Test</p>';
//}
//dsm($form);
}
}
Comments
Found out that my endless
Found out that my endless spinner was caused by a JavaScript error: Drupal.Views.Ajax.handleErrors is not a function. Only thing I can find out there is that ajax_view.js is included but ajax.js (which contains the function Drupal.Views.Ajax.handleErrors) is not included. Forcing it in with drupal_add_js caused a rather strange error -- a box popped up with this:
An error occurred at /views/ajax.
Error Description: Test{ "status": true, "display": "\x3cdiv class=\"view view-today view-id-today view-display-id-block_1 view-dom-id-5\"\x3e\r\n \x3cdiv class=\"views-admin-links views-hide\"\x3e\r\n \x3cul class=\"links\"\x3e\x3cli class=\"0 first\"\x3e\x3ca href=\"/admin/build/views/edit/today?destination=node%2F1%3Fv%5Bvalue%5D%5Bmonth%5D%3D5%26v%5Bvalue%5D%5Bday%5D%3D11%26v%5Bvalue%5D%5Byear%5D%3D2011%26view_name%3Dtoday%26view_display_id%3Dblock_1%26view_args%3D%26view_path%3Dnode%252F1%26view_base_path%3Dnull%26view_dom_id%3D5%26pager_element%3D0#views-tab-block_1\"\x3eEdit\x3c/a\x3e\x3c/li\x3e\n\x3cli class=\"1\"\x3e\x3ca href=\"/admin/build/views/export/today\"\x3eExport\x3c/a\x3e\x3c/li\x3e\n\x3cli class=\"2 last\"\x3e\x3ca href=\"/admin/build/views/clone/today\"\x3eClone\x3c/a\x3e\x3c/li\x3e\n\x3c/ul\x3e \x3c/div\x3e\r\n \x3cdiv class=\"view-header\"\x3e\r\n \x3cp\x3e\x3cimg src=\"/sites/all/themes/zoo/images/today_at_the_zoo.jpg\" alt=\"Today at the Zoo\" /\x3e\x3c/p\x3e\n \x3c/div\x3e\r\n \r\n \r\n \x3cdiv class=\"view-content\"\x3e\r\n \x3cdiv class=\"views-row views-row-1 views-row-odd views-row-first\"\x3e\n \n \x3cspan class=\"views-field-field-event-date-value\"\x3e\n \x3cspan class=\"field-content\"\x3e\x3ca href=\"/events/meet-locals\"\x3e\x3cspan class=\"date-display-single\"\x3e11:00 AM\x3c/span\x3e\x3c/a\x3e\x3c/span\x3e\n \x3c/span\x3e\n - \n \x3cspan class=\"views-field-title\"\x3e\n \x3cspan class=\"field-content\"\x3e\x3ca href=\"/events/meet-locals\"\x3eMeet the Locals\x3c/a\x3e\x3c/span\x3e\n \x3c/span\x3e\n \x3c/div\x3e\n \x3cdiv class=\"views-row views-row-2 views-row-even views-row-last\"\x3e\n \n \x3cspan class=\"views-field-field-event-date-value\"\x3e\n \x3cspan class=\"field-content\"\x3e\x3ca href=\"/events/keeper-talks-cougar\"\x3e\x3cspan class=\"date-display-single\"\x3e3:30 PM\x3c/span\x3e\x3c/a\x3e\x3c/span\x3e\n \x3c/span\x3e\n - \n \x3cspan class=\"views-field-title\"\x3e\n \x3cspan class=\"field-content\"\x3e\x3ca href=\"/events/keeper-talks-cougar\"\x3eKeeper Talks: Cougar\x3c/a\x3e\x3c/span\x3e\n \x3c/span\x3e\n \x3c/div\x3e\n \x3c/div\x3e\r\n \r\n \r\n \r\n \r\n \r\n \x3cdiv class=\"view-filters\"\x3e\r\n \x3cform action=\"/\" accept-charset=\"UTF-8\" method=\"get\" id=\"views-exposed-form-today-block-1\"\x3e\n\x3cdiv\x3e\x3cdiv class=\"views-exposed-form\"\x3e\n \x3cdiv class=\"views-exposed-widgets clear-block\"\x3e\n \x3cdiv class=\"views-exposed-widget\"\x3e\n \x3cdiv class=\"views-widget\"\x3e\n \x3cdiv class=\"date-views-filter-wrapper\"\x3e\n\x3cdiv class=\"container-inline-date date-clear\"\x3e\n\x3c/div\x3e\n\x3cdiv class=\"date-clear form-item\"\x3e\x3cdiv class=\"description\"\x3e\n \x3cdiv class=\"container-inline-date date-clear-block\"\x3e\x3cdiv class=\"form-item\" id=\"edit-v-value-wrapper\"\x3e\n \x3cdiv class=\"date-month\"\x3e\x3cdiv class=\"form-item\" id=\"edit-v-value-month-wrapper\"\x3e\n \x3cselect name=\"v[value][month]\" class=\"form-select date-month\" id=\"edit-v-value-month\" \x3e\x3coption value=\"\"\x3e-Month\x3c/option\x3e\x3coption value=\"1\"\x3eJanuary\x3c/option\x3e\x3coption value=\"2\"\x3eFebruary\x3c/option\x3e\x3coption value=\"3\"\x3eMarch\x3c/option\x3e\x3coption value=\"4\"\x3eApril\x3c/option\x3e\x3coption value=\"5\" selected=\"selected\"\x3eMay\x3c/option\x3e\x3coption value=\"6\"\x3eJune\x3c/option\x3e\x3coption value=\"7\"\x3eJuly\x3c/option\x3e\x3coption value=\"8\"\x3eAugust\x3c/option\x3e\x3coption value=\"9\"\x3eSeptember\x3c/option\x3e\x3coption value=\"10\"\x3eOctober\x3c/option\x3e\x3coption value=\"11\"\x3eNovember\x3c/option\x3e\x3coption value=\"12\"\x3eDecember\x3c/option\x3e\x3c/select\x3e\n\x3c/div\x3e\n\x3c/div\x3e\x3cdiv class=\"date-day\"\x3e\x3cdiv class=\"form-item\" id=\"edit-v-value-day-wrapper\"\x3e\n \x3cselect name=\"v[value][day]\" class=\"form-select date-day\" id=\"edit-v-value-day\" \x3e\x3coption value=\"\"\x3e-Day\x3c/option\x3e\x3coption value=\"1\"\x3e1\x3c/option\x3e\x3coption value=\"2\"\x3e2\x3c/option\x3e\x3coption value=\"3\"\x3e3\x3c/option\x3e\x3coption value=\"4\"\x3e4\x3c/option\x3e\x3coption value=\"5\"\x3e5\x3c/option\x3e\x3coption value=\"6\"\x3e6\x3c/option\x3e\x3coption value=\"7\"\x3e7\x3c/option\x3e\x3coption value=\"8\"\x3e8\x3c/option\x3e\x3coption value=\"9\"\x3e9\x3c/option\x3e\x3coption value=\"10\"\x3e10\x3c/option\x3e\x3coption value=\"11\" selected=\"selected\"\x3e11\x3c/option\x3e\x3coption value=\"12\"\x3e12\x3c/option\x3e\x3coption value=\"13\"\x3e13\x3c/option\x3e\x3coption value=\"14\"\x3e14\x3c/option\x3e\x3coption value=\"15\"\x3e15\x3c/option\x3e\x3coption value=\"16\"\x3e16\x3c/option\x3e\x3coption value=\"17\"\x3e17\x3c/option\x3e\x3coption value=\"18\"\x3e18\x3c/option\x3e\x3coption value=\"19\"\x3e19\x3c/option\x3e\x3coption value=\"20\"\x3e20\x3c/option\x3e\x3coption value=\"21\"\x3e21\x3c/option\x3e\x3coption value=\"22\"\x3e22\x3c/option\x3e\x3coption value=\"23\"\x3e23\x3c/option\x3e\x3coption value=\"24\"\x3e24\x3c/option\x3e\x3coption value=\"25\"\x3e25\x3c/option\x3e\x3coption value=\"26\"\x3e26\x3c/option\x3e\x3coption value=\"27\"\x3e27\x3c/option\x3e\x3coption value=\"28\"\x3e28\x3c/option\x3e\x3coption value=\"29\"\x3e29\x3c/option\x3e\x3coption value=\"30\"\x3e30\x3c/option\x3e\x3coption value=\"31\"\x3e31\x3c/option\x3e\x3c/select\x3e\n\x3c/div\x3e\n\x3c/div\x3e\x3cdiv class=\"date-year\"\x3e\x3cdiv class=\"form-item\" id=\"edit-v-value-year-wrapper\"\x3e\n \x3cselect name=\"v[value][year]\" class=\"form-select date-year\" id=\"edit-v-value-year\" \x3e\x3coption value=\"\"\x3e-Year\x3c/option\x3e\x3coption value=\"2008\"\x3e2008\x3c/option\x3e\x3coption value=\"2009\"\x3e2009\x3c/option\x3e\x3coption value=\"2010\"\x3e2010\x3c/option\x3e\x3coption value=\"2011\" selected=\"selected\"\x3e2011\x3c/option\x3e\x3coption value=\"2012\"\x3e2012\x3c/option\x3e\x3coption value=\"2013\"\x3e2013\x3c/option\x3e\x3coption value=\"2014\"\x3e2014\x3c/option\x3e\x3c/select\x3e\n\x3c/div\x3e\n\x3c/div\x3e\n\x3c/div\x3e\n\x3c/div\x3e\x3c/div\x3e\n\x3c/div\x3e\n\x3c/div\x3e \x3c/div\x3e\n \x3c/div\x3e\n \x3cdiv class=\"views-exposed-widget\"\x3e\n \x3cinput type=\"submit\" id=\"edit-submit-today\" value=\"Apply\" class=\"form-submit\" /\x3e\n \x3c/div\x3e\n \x3c/div\x3e\n\x3c/div\x3e\n\x3c/div\x3e\x3c/form\x3e\n \x3c/div\x3e\r\n \r\n \r\n\x3c/div\x3e ", "title": "", "__callbacks": [ "Drupal.Views.Ajax.ajaxViewResponse" ], "messages": "\x3cdiv class=\"views-messages\"\x3e\x3cdiv class=\"messages status\"\x3e\n\x3ca href=\"/admin/settings/site-maintenance\"\x3eOperating in off-line mode.\x3c/a\x3e\x3c/div\x3e\n\x3c/div\x3e" }
...and now I'm completely lost.
Alright, getting closer. I
Alright, getting closer. I apologize for working through this on the forums but perhaps this will help someone else who's interested in doing something similar.
I had created a views-view--myview.tpl.php in order to rearrange the content and the exposed form, so I added the following code to the top of the page:
today being the name of my view and v being the filter identifier. And this works -- it displays the full date from which I can easily extract the month and date for display. But my new problem is that every time the form is submitted I get a new date in the session variable -- rather than replacing the value it somehow adds an additional one and I can't seem to be able to reference one from another.
I'm now assuming it's got
I'm now assuming it's got something to do with either set_exposed_input(), get_exposed_input(), or exposed_info() though I can't figure out how to get anything out of those at all.
Way too complicated
As usual, I made it way too complicated for myself. I still have no idea how to retrieve the value of an ajax submitted exposed form but it turns out that simply grabbing an extra copy of the date field and sorting by that field (under Style: Unformatted options) accomplished the same thing. Since all events were selected on a specific day, I can display the field and then position:absolute it up to where it needs to be.
Well, one more update that
Well, one more update that makes this work a lot better. My previous solution had one flaw: if there were no records then the date would not display at all. I really wanted to display the date so that the visitor would have visual confirmation of the date that they searched.
My new solution is to add PHP Code to the Header which checks for useful data in $view->exposed_input like so:
Sorry if this whole thing is painfully obvious to other developers but I couldn't find anything about it for the life of me. If anyone else is in the same boat, hopefully this will help them!
$view =
$view = views_get_current_view();
$view->exposed_input['nid']
Just worked for us. Thanks for posting this. Crazy that you posted this 5 hours ago and I just found it on Google.