Sha256: b491760501dc30d726468895c827c9b352efa67bf5cbb559c9a2394a6e7513a3

Contents?: true

Size: 1.11 KB

Versions: 30

Compression:

Stored size: 1.11 KB

Contents

import { Controller } from "@hotwired/stimulus"
import { FetchRequest } from '@rails/request.js'

export default class extends Controller {
  static values = {
    submitUrl: String
  }


  search(event) {
    event.preventDefault()
    this.submitFilter()
    document.activeElement.blur()
  }

  async submitFilter() {
    const {blueprint} = this.stateController
    const request = new FetchRequest(
      "POST",
      this.submitUrlValue,
      {
        responseKind: "turbo-stream",
        body: JSON.stringify({
          refine_filters_builder: {
            filter_class: this.stateController.filterName,
            blueprint_json: JSON.stringify(blueprint),
            client_id: this.stateController.clientIdValue
          }
        })
      }
    )
    await request.perform()
  }

  get stateController() {
    return this
      .element
      .querySelector('[data-controller~="refine--state"]')
      .refineStateController
  }

  loadResults({detail: {url}}) {
    console.log("filter submit success")
    if (window.Turbo) {
      window.Turbo.visit(url)
    } else {
      window.location.href = url
    }
  }
}

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
refine-rails-2.12.0 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.12 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.11 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.10 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.9 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.8 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.6 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.5 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.4 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.3 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.2 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.1 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.11.0 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.10.1 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.10.0 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.9.14 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.9.13 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.9.12 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.9.11 app/javascript/controllers/refine/search-filter-controller.js
refine-rails-2.9.10 app/javascript/controllers/refine/search-filter-controller.js