Hello,

I have an ajax view that have one required exposed filter.

When the user don't fill the exposed filter and click on the submit button, the field is marked in red, as a required filter, but no error messages appears.

If I disable ajax view functionnality and that I do the same thing, the "field xxx is required" message appears normally.

The ajax view should display that message too, it's not user friendly to have that field marked in red, without explaination at all.

Regards,

Alex

Comments

dancor’s picture

bump

pingevt’s picture

Issue summary: View changes

I'm having the same issue. Since the last comment has been almost a year ago, has there been any progress or thoughts on this issue?

My situation:
I'm using views Better Exposed Filters, auto submit and ajax. I have an optional search terms Filter. Normal search, if it is less than 3 characters you get an error saying, "You must include at least one positive keyword with 3 characters or more". This error does not show up until you navigate away form the page.

I've also tried using the basic form, ajax and no auto submit. Still no error message. So I believe it is an issue with the ajax.

I'll be looking into this and let you know my progress.

pingevt’s picture

Well, I'm not entirely sure about a patch yet, but comparing drupal's and view's aja callback, views is never looking for status messages. However, there is a hook alter, hook_views_ajax_data_alter(). SO i added this to my module and seems to be working at the moment.

function MODULE_views_ajax_data_alter(&$commands, $view) {
$commands[] = ajax_command_prepend($commands[0]['selector'], theme('status_messages'));
}

So is this something that should be in Views, or something that should be done by developers?

langelhc’s picture

@pingevt Thank you,

I used the same hook_views_ajax_data_alter() and works.

And IMHO this should be in views, because if the message is not rendered is stored until the reload or maybe if the user opens a new tab it's showed a bunch of errors.

DrIPA’s picture

Thanks #3 works

nghai’s picture

Similar issue opened for Drupal 8: https://www.drupal.org/project/drupal/issues/2977785

If anybody having any idea. Please update there.

james.williams’s picture

I can confirm I've seen this bug too - not just for the error message about required form elements, but in fact any messages (including errors, but anything else too) that occur during an AJAX request. The messages only show up on the next full page request.

This is because the page callback for views' AJAX responses, views_ajax(), returns a render array with '#type' => 'ajax', so ajax_prepare_response() (called from the delivery callback for normal AJAX requests) follows a different code path to the one that would be used for page callbacks that just return regular render arrays or strings, which does add status messages.

So I suspect views_ajax() ought to ensure to include prepending any messages in its response?

james.williams’s picture

Title: No error messages with required exposed filters on ajax view » Error messages not shown when using ajax with a view
james.williams’s picture

Version: 7.x-3.5 » 7.x-3.x-dev