我尝试在搜索中实现自动填充字段。声明所有依赖项后,控制台页面始终显示我的函数自动完成不存在:
见
PHP
$form['basic']['keys'] = array(
'#type' => 'search',
'#title' => $this->t('Digite sua pesquisa'),
'#default_value' => $keys,
'#size' => 30,
'#maxlength' => 255,
);
$form['#attached']['library'][] = 'busca/busca_form';
$form['basic']['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('Search'),
我的js
$(document).ready(function(){
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
];
$("#edit-keys" ).autocomplete({
source: availableTags
});
});
和我的图书馆
busca_form: version: VERSION js: js/complete.js: {} dependencies: - core/jquery - core/drupal.ajax - core/drupal - core/drupalSettings - core/jquery.once - core/jquery.ui.autocomplete
错误:complete.js?v = 8.1.2:35未捕获TypeError:$(...)。autocomplete不是函数(...)
任何想法? TKS
答案 0 :(得分:0)
这样在这里工作正常。
(function ($, Drupal, drupalSettings, doc) {
"use strict";
Drupal.behaviors.Myautocomplete = {
attach: function myFunc(context, settings) {
var options = ["Java", "Jaca"];
jQuery("#lookfor").autocomplete({
source: options
});
},
};
})(jQuery, Drupal, drupalSettings, document);