Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
dancor CreditAttribution: dancor commentedbump
Comment #2
pingevt CreditAttribution: pingevt commentedI'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.
Comment #3
pingevt CreditAttribution: pingevt commentedWell, 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?
Comment #4
langelhc CreditAttribution: langelhc commented@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.
Comment #5
DrIPA CreditAttribution: DrIPA commentedThanks #3 works
Comment #6
nghai CreditAttribution: nghai commentedSimilar issue opened for Drupal 8: https://www.drupal.org/project/drupal/issues/2977785
If anybody having any idea. Please update there.
Comment #7
james.williams CreditAttribution: james.williams at ComputerMinds commentedI 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'
, soajax_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?Comment #8
james.williams CreditAttribution: james.williams at ComputerMinds commentedComment #9
james.williams CreditAttribution: james.williams at ComputerMinds commented