Код: Выделить всё
var autoComplete = (function(){
[ ... contents of .js file. see below]
var demo1 = new autoComplete({
selector: '#user_municipal_other',
minChars: 1,
source: function(term, suggest){
term = term.toLowerCase();
var choices = ;
var suggestions = [];
for (var i = 0; i < choices.length; i += 1) {
if (choices[i].toLowerCase().indexOf(term) !== -1) suggestions.push(choices[i]);
}
suggest(suggestions);
}
});
закрепление двух версий, отдельных попыток, в importmap.rb
Код: Выделить всё
pin "pixabay-javascript-autocomplete", to: "https://ga.jspm.io/npm:pixabay-javascript-autocomplete@1.0.4/auto-complete.min.js"
pin "auto-complete", to: "auto-complete.js"
Код: Выделить всё
application.jsКод: Выделить всё
import PixabayJavascriptAutocomplete from "pixabay-javascript-autocomplete"
import AutoComplete from "auto-complete"
В обоих случаях консоль жалуется, что Uncaught ReferenceError: autoComplete не определен, ссылаясь на строку var demo1 = new autoComplete javascript_tag. Таким образом, скрипт на странице не обращается к скрипту, загруженному в шапку
Код: Выделить всё
Код: Выделить всё
import AutoCompleteMunController from "./auto_complete_mun_controller"
application.register("auto-complete", AutoCompleteMunController)
Код: Выделить всё
import { Controller } from "@hotwired/stimulus";
// initialize only when the page / element exists
// use turbo:load for Turbo Drive support (or DOMContentLoaded if not using Turbo)
document.addEventListener("turbo:load", () => {
const el = document.querySelector("#user_municipal_other");
if (!el) return;
new autoComplete({
selector: '#user_municipal_other',
minChars: 1,
source: function(term, suggest){
term = term.toLowerCase();
var choices = ;
var suggestions = [];
for (var i = 0; i < choices.length; i += 1) {
if (choices[i].toLowerCase().indexOf(term) !== -1) suggestions.push(choices[i]);
}
suggest(suggestions);
}
});
});
Подробнее здесь: https://stackoverflow.com/questions/798 ... pt-failing
Мобильная версия