I have a library + a secondary script that calls up instance variables to run with the main script. The source library has no apparent reliable source with which one can pin.
Placing it a page via tags followed by the contextual script
<%= javascript_tag do %>
var demo1 = new autoComplete({
selector: '#user_municipal_other',
minChars: 1,
source: function(term, suggest){
term = term.toLowerCase();
var choices = <%= raw @municipal_names %>;
var suggestions = [];
for (var i = 0; i < choices.length; i += 1) {
if (choices[i].toLowerCase().indexOf(term) !== -1) suggestions.push(choices[i]);
}
suggest(suggestions);
}
});
<% end %>
runs as expected.
The first goal is to have the main library script loaded across the entire app. I placed autoComplete.js in path javascript/vendor
How should this be invoked then? Can it be pinned and know to find it in /vendor ?
Should it be subject of an import in javascript/controllers/index.js ... I cannot do something equivalent to
import {
PasswordConfirmController,
PasswordPeekController,
} from "stimulus-library";
as autoComplete is not pinned.
Subsequently, can the <%= javascript_tag still be placed in the view - or should it be object of a different controller in proper rails fashion? initial preference is to keep the tag in the page as the selector and instance variable are relative & adapted to said view