Sometimes, it is very handfull to pass to autocomplete route additional parameters, not only the text that come from input textfield.

Example: Form with field "City" (select) and "Street" (autocomplete). I want to search streets only in chosen city.

Yes, I know I can make "#ajax" property for "City" field, then on form ajax rebuild pass the city id to "'#autocomplete_route_parameters' => array('city' => 13)," property of "Street" form field. (I didn't test that way yet).

But there is a way better, without additional ajax requests.

I want to add custom js library, that handle changes of "City" field, and on change it would do something like this:

jQuery.extend(true, Drupal.autocomplete.ajax, {data: {city: 13}});

But then autocomplete should make recursive merge of Drupal.autocomplete.ajax. Please see the patch and jQuery.extend doc: http://api.jquery.com/jquery.extend/

CommentFileSizeAuthor
improve_autocomplete.js_.patch550 bytesandyceo
PASSED: [[SimpleTest]]: [PHP 5.5 MySQL] 97,317 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

andypost’s picture

Issue tags: -JS +JavaScript
andyceo’s picture

Issue summary: View changes
markdorison’s picture

Version: 8.0.0-beta12 » 8.3.x-dev
Assigned: andyceo » Unassigned
droplet’s picture

I like the patch but worrying about the backward compatibility

andypost’s picture

@droplet please point where it breaks BC? I suppose it implementation details that does not affect contrib

droplet’s picture

@andypost,

We didn't expect deep copy before. Data are not filtered in CORE / Contrib.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.