Skip to content

Instantly share code, notes, and snippets.

@secretpray
Last active July 7, 2022 08:01
Show Gist options
  • Save secretpray/dba958c6fcd2fcd672a0b6d80879706d to your computer and use it in GitHub Desktop.
Save secretpray/dba958c6fcd2fcd672a0b6d80879706d to your computer and use it in GitHub Desktop.
  1. In target Stimulus Controller
connect() {
  this.element[this.identifier] = this
 }

or if name have special symbol (like auto_search_controller.js -> auto-search)

connect() {
  this.element[ (str => { return str
                          .split('--')
                          .slice(-1)[0]
                          .split(/[-_]/)
                          .map(w => w.replace(/./, m => m.toUpperCase()))
                          .join('')
                          .replace(/^\w/, c => c.toLowerCase())
                      }
              )(this.identifier)
            ] = this 
}

to call function from this controller

document.querySelector("#filters-price-section").priceSelect.fullPriceRangeReset()

where

document.querySelector("#filters-price-section") // target DOM element ths controller name
fullPriceRangeReset() // function in this Stimulus controller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment