dpc
June 3, 2016, 12:54pm
1
I want to use autocomplete.js in my theme. I can add autocomplete.js easily enough to the final main.js but it doesn’t work. I’ve tried adding the core too but the same result.
Is this the right way to be doing this and if not what is the best method? Any help appreciated.
(I’ve read the docs and searched extensively)
the bower.json
"dependencies": {
"jquery": "~2.1.4",
"waypoints": "jquery-waypoints#^4.0.0",
"jquery-ui": "^1.11.4"
},
"overrides": {
"waypoints": {
"main": [
"./lib/jquery.waypoints.min.js"
]
},
"jquery-ui": {
"main": [
"./ui/core.js",
"./ui/autocomplete.js"
]
}
},
error is -
main.js:6:9516
TypeError: e.widget is not a function. (In ‘e.widget’, ‘e.widget’ is undefined)
return e.widget(“ui.autocomplete”, {
cfx
June 3, 2016, 1:03pm
2
How and where are you invoking it?
dpc
June 3, 2016, 1:10pm
3
Hey cfx, in
var Sage = {
// All pages
'common': { ...etc
...finalize: function() {
// JavaScript to be fired on all pages, after page specific JS is fired
var availableTags = [
"ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++",
"Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran",
"Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl",
"PHP", "Python", "Ruby", "Scala", "Scheme"
];
$(".search-field").autocomplete({
source: availableTags
}); ...
It works if i include the whole jQuery-ui.js
D.
cfx
June 3, 2016, 1:38pm
4
That’s because your overrides are omitting several autocomplete dependencies .
dpc
June 3, 2016, 1:49pm
5
ok - isn’t this what this is for?
“./ui/core.js”,
cfx
June 3, 2016, 1:51pm
6
Did you check the dependencies in the link above? Core is only one dependency.
dpc
June 3, 2016, 2:14pm
7
ah ha!
I see. I always have so much trouble with adding scripts to this workflow that i always presume i’ve done it in the wrong file or place.
This now works so thanks for your patience.
"overrides": {
"waypoints": {
"main": [
"./lib/jquery.waypoints.min.js"
]
},
"jquery-ui": {
"main": [
"./ui/core.js",
"./ui/widget.js",
"./ui/position.js",
"./ui/menu.js",
"./ui/autocomplete.js"
]
}
},
cfx
June 3, 2016, 2:42pm
8
Sure thing glad you got it