Sha256: 1d655aa537781b722ab49645dd7a6260cd900c9c9194c0529e9a15b8bd905e0e

Contents?: true

Size: 1.23 KB

Versions: 30

Compression:

Stored size: 1.23 KB

Contents

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  connect() {
    this.state = this.getStateController()
    this.blueprintInput = this.addHiddenInput('blueprint')
    this.addHiddenInput('filter', this.state.filterName)
    this.addHiddenInput('form_id', this.state.formIdValue)
    this.finishUpdate()
  }

  getStateController() {
    let currentElement = this.element

    while(currentElement !== document.body) {
      const controller = this.application.getControllerForElementAndIdentifier(currentElement, 'refine--state')
      if (controller) {
        return controller
      } else {
        currentElement = currentElement.parentNode
      }
    }

    return null
  }

  addHiddenInput(name, initialValue) {
    const input = document.createElement('input')
    input.type = 'hidden'
    input.name = name
    input.value = initialValue || ''
    this.element.appendChild(input)
    return input
  }

  // called on connect
  finishUpdate() {
    this.state.finishUpdate()
  }

  // Call this on submit
  startUpdate() {
    this.blueprintInput.value = JSON.stringify(this.state.blueprint)
    this.state.startUpdate()
  }

  submitForm() {
    this.startUpdate()
    this.element.requestSubmit()
  }
}

Version data entries

30 entries across 30 versions & 1 rubygems

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