Sha256: ccf19bf5aff61818052e41d6782bcb8ed1ad281e36c746a7d7fa895052feb326

Contents?: true

Size: 582 Bytes

Versions: 45

Compression:

Stored size: 582 Bytes

Contents

import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  static targets = ['select', 'type', 'container']

  connect() {
    this.changeType() // Do the initial type change
  }

  changeType() {
    this.#hideAllTypes()
    this.#showType(this.selectTarget.value)
  }

  #hideAllTypes() {
    this.containerTarget.innerHTML = ''
  }

  #showType(type) {
    const target = this.typeTargets.find((typeTarget) => typeTarget.dataset.type === type)
    if (target) {
      this.containerTarget.appendChild(target.content.cloneNode(true))
    }
  }
}

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
avo-3.15.1 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.15.0 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.14.5 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.14.4 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.14.3 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.14.2 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.14.1 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.14.0 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.13.7 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.13.6 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.13.5 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.13.4 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.13.3 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.13.2 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.13.1 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.13.0 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.12.0 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.11.10 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.11.9 app/javascript/js/controllers/fields/belongs_to_field_controller.js
avo-3.11.8 app/javascript/js/controllers/fields/belongs_to_field_controller.js