जवाबों:
कोई घटना (7.34) के रूप में इस समय शुरू हो रहा है, लेकिन वहाँ पर एक पैच है इस मुद्दे को आप की तरह कुछ का उपयोग करते हैं चाहिए कि:
$('#input-id').on('autocompleteSelect', function(event, node) {
});
या यदि आप jQuery के पुराने संस्करण का उपयोग कर रहे हैं
$('#input-id').bind('autocompleteSelect', function(event, node) {
});
nodeचयनित आइटम कहां है आपको tidउस ऑब्जेक्ट पर एक गुण से प्राप्त करने में सक्षम होना चाहिए ।
Drupal 7 और 8 इस समय बिना किसी कस्टम कोड के jQuery के स्वतः पूर्ण ईवेंट जनरेशन प्रदान करते हैं।
Drupal 7 में, autocompleteSelectDrupal समस्या # 365241 में ईवेंट जोड़ा गया था । (क्लाइव ने इस बात का उल्लेख किया था जब उन्होंने अपनी प्रतिक्रिया पोस्ट की थी।)
Drupal 8 jQuery UI स्वतः पूर्ण विजेट का उपयोग करता है । autocompletecloseघटना D7 के लिए सबसे समान jQuery यूआई घटना है autocompleteSelectघटना। D8 में jQuery UI autocompleteselectईवेंट को भी ट्रिगर किया जाएगा लेकिन इस पर एक अजाक्स कॉलबैक अपडेटेड फॉर्म स्टेट मान प्राप्त नहीं करेगा। autocompletecloseकॉलबैक अद्यतन प्रपत्र राज्य मूल्यों के साथ प्रदान किए जाते हैं, जो आमतौर पर आप चाहते हैं।
जैसा कि अन्य उत्तरों ने संकेत दिया है, आप इवेंट हैंडलर, या Drupal.behaviors ( Drupal 7 , Drupal 8 ) पर jQuery का उपयोग करके क्लाइंट ब्राउज़र में ईवेंट डेटा का उपयोग कर सकते हैं । Drupal 7 में आप घटना का उपयोग करेंगे , और Drupal 8 पर ।autocompleteSelectautocompleteclose
यदि आपको अपने PHP कोड में मूल्य की आवश्यकता है, तो एक अजाक्स कॉलबैक का उपयोग किया जा सकता है। Drupal 7 में या Drupal 8 में यह कैसे किया जाए, इसके लिए कुछ निर्देश दिए गए हैं ।
मुझे इसे काम करने के लिए एक व्यवहार का उपयोग करने की आवश्यकता थी (क्लाइव द्वारा बताई गई समस्या के लिए धन्यवाद, और यह टिप्पणी: https://www.drupal.org/node/365241#comment-9575707 ):
Drupal.behaviors.autocompleteSupervisor = {
attach: function (context) {
$('#edit-field-foo-und-0-target-id', context).bind('autocompleteSelect', function(event, node) {
// Do custom stuff here...
var entity_id = $(this).val().replace($(node).text().trim(), '').replace(/\(|\)| /g, '');
});
}
};
Drupal 8 में यह स्थानांतरित हो गया है। आप निम्न कोड के साथ कार्यक्षमता को ओवरराइड कर सकते हैं।
/**
* Handles an autocompleteselect event.
*
* Override the autocomplete method to add a custom event.
*
* @param {jQuery.Event} event
* The event triggered.
* @param {object} ui
* The jQuery UI settings object.
*
* @return {bool}
* Returns false to indicate the event status.
*/
Drupal.autocomplete.options.select = function selectHandler(event, ui) {
var terms = Drupal.autocomplete.splitValues(event.target.value);
// Remove the current input.
terms.pop();
// Add the selected item.
if (ui.item.value.search(',') > 0) {
terms.push('"' + ui.item.value + '"');
}
else {
terms.push(ui.item.value);
}
event.target.value = terms.join(', ');
// Fire custom event that other controllers can listen to.
jQuery(event.target).trigger('autocomplete-select');
// Return false to tell jQuery UI that we've filled in the value already.
return false;
}
में कोड ओवरराइड करता है core/misc/autocomplete.js।
फिर आपके कोड में आप सुन सकते हैं
var field = jQuery('<field-selector>');
var lastField = ''
field.on('autocomplete-select', function() {
console.log("autocompleteSelect");
// Check that field actually changed.
if ($(this).val() != lastValue) {
lastValue = $(this).val();
console.log('The text box really changed this time');
}
})