-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Allow to use local HTML instead of fetching from the server #116
Comments
I just tried abusing a data URL for this: <div data-controller="autocomplete" data-autocomplete-url-value="data:text/html,%3Cli%20class%3D%22list-group-item%22%20role%3D%22option%22%20data-autocomplete-value%3D%221%22%3EBlackbird%3C%2Fli%3E%0A%3Cli%20class%3D%22list-group-item%22%20role%3D%22option%22%20data-autocomplete-value%3D%222%22%3EBluebird%3C%2Fli%3E%0A%3Cli%20class%3D%22list-group-item%22%20role%3D%22option%22%20data-autocomplete-value%3D%223%22%3EMockingbird%3C%2Fli%3E%0A">
<input name="birds" type="text" class="form-control" data-autocomplete-target="input" placeholder="search a bird" autofocus/>
<input type="hidden" name="bird_id" data-autocomplete-target="hidden"/>
<ul data-autocomplete-target="results" class="list-group"></ul>
</div> It works partially 🤣 CleanShot.2022-09-23.at.14.53.24.mp4 |
@fidalgo if you just want to solve this issue for a particular feature you could override <div data-controller="combobox" data-combobox-options-value="[JSON array with options]">
...
</div> class Combobox extends Autocomplete {
static values = { options: Array }
doFetch = async () => {
const query = this.inputTarget.value.trim().toLowerCase()
const matchingOptions = this.optionsValue.filter(o => o.toLowerCase.includes(query))
return matchingOptions.map(o => `<li data-autocomplete-value="${o}">${o}</li>`).join("\n")
}
} If however you wan to add the feature to the library, I'd suggest going in the opposite direction: create a base I'd be happy to accept patches implementing that, although it seems a substantial change. |
+1 |
Hi! First of all, thank you for your work on this!
If we allow using HTML data attributes with data in JSON format instead of fetching from the server, this will allow caching where the data is static while preventing more network requests.
Imagine the case of a country list, where it's a fixed list; we may want just to iterate and render the
li
elements, but currently, we cannot use the autocomplete.Do you think this could be a nice addition to this lib?
The text was updated successfully, but these errors were encountered: