Skip to content

Form duplication on back navigation #21

@pardeyke

Description

@pardeyke

I'm using [use-bootstrap-select] in my Ruby on Rails app together with a Stimulus controller:
this.select = new UseBootstrapSelect(this.element)

When navigating to another page and then using the back button in the browser the select forms are now visually duplicated. One of them is not working though.
I've come up with a bit hacky workaround.
I am assigning unique ids to my select tags, so that it's possible to have multiple instances:

document.querySelectorAll(`[data-select-id="${this.element.id}"]`).forEach((el) => {
      el.remove()
})
this.select = new UseBootstrapSelect(this.element)
const bootstrap_select = this.element.nextElementSibling
bootstrap_select.setAttribute("data-select-id", this.element.id)

It's not possible to check if new UseBootstrapSelect has been called on an element or not. And also the generated .use-bootstrap-select-wrapper can not be linked back to the element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions