Sha256: 6b0b1de87985c541bb69b52f81190f50a6fe9b5d41f044f2cccc2ef69e961b9e

Contents?: true

Size: 799 Bytes

Versions: 6

Compression:

Stored size: 799 Bytes

Contents

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  
  static get targets() {
    return ['input', 'label', 'search']
  }
  
  connect() {
    // Show placeholder if there is no page selected yet
    if (this.labelTarget.querySelector("turbo-frame") == undefined) {
      this.clear()
    }
  }
  
  select(event) {
    let button = event.currentTarget
    
    this.inputTarget.value = button.dataset.id
    this.labelTarget.innerText = button.dataset.title
  }
  
  clear() {
    this.inputTarget.value = ""
    this.labelTarget.innerHTML = `
      <span class="text-gray-400">
        ${this.element.dataset.placeholder}
      </span>
    `
  }
  
  autofocus() {
    setTimeout(function() {
      this.searchTarget.focus()
    }.bind(this), 100)
  }
  
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spina-2.18.0 app/assets/javascripts/spina/controllers/page_select_controller.js
spina-2.17.0 app/assets/javascripts/spina/controllers/page_select_controller.js
spina-2.16.0 app/assets/javascripts/spina/controllers/page_select_controller.js
spina-2.15.1 app/assets/javascripts/spina/controllers/page_select_controller.js
spina-2.15.0 app/assets/javascripts/spina/controllers/page_select_controller.js
spina-2.14.0 app/assets/javascripts/spina/controllers/page_select_controller.js