josefarias / hotwire_combobox

An accessible autocomplete for Ruby on Rails.
https://hotwirecombobox.com
MIT License
496 stars 32 forks source link

JS Error when clicking value: Missing target element "mainWrapper" for "hw-combobox" controller #104

Closed dylandamsma closed 7 months ago

dylandamsma commented 7 months ago

Describe the bug Clicking on a value does not close the combobox and invokes a JS error

To Reproduce Steps to reproduce the behavior:

  1. Using EsBuild
  2. Using combobox in a form

/javascript/controllers/application.js

import { Application } from "@hotwired/stimulus"

const application = Application.start()

import HwComboboxController from "@josefarias/hotwire_combobox"
application.register("hw-combobox", HwComboboxController)

// Configure Stimulus development experience
application.debug = false
window.Stimulus   = application

export { application }

form

<div class="relative grow">
    <%= f.combobox :province_eq, location_options('provinces', 'name', 'slug'), open: false, value: @tournament.province %>
    <i class="fa-regular fa-location-dot absolute top-2.5 left-3.5 text-gray-400"></i>
</div>

Expected behavior Combobox to select value and close

Additional context Combobox stays open after clicking value:

Screenshot 2024-03-13 at 6 56 42 PM

josefarias commented 7 months ago

Hey @dylandamsma sorry you're having trouble with the library.

Just tried this on a fresh rails app and it seems to work for me. Is it possible there's a version mismatch between your npm and gem hotwire_combobox libraries? They should be the same version. Maybe you updated one and not the other?

If that isn't the case, could you please provide which version of the gem you're on (check Gemfile.lock), which version of the JS package you're on (check yarn.lock or package.lock), and/or an example application where this is happening? Would also be curious to see the implementation of location_options

Thanks! Closing for now but do let me know if it's not a version mismatch and I'll reopen.

dylandamsma commented 7 months ago

Apologies, I had removed it from my Gemfile previously -- but the Gemfile.lock still kept it on old version

josefarias commented 7 months ago

No worries! Glad we found the problem 👍