Sha256: f905f9cb98251d27840076d5049f1b13ed4440d80280b1c0faf410b886178517

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  static get targets () {
    return ['original', 'operator', 'null']
  }

  connect () {
    this.operatorTarget.addEventListener('change', () => this.handleOperatorChange())
    this.handleOperatorChange()
  }

  handleOperatorChange () {
    if (this.operatorTarget.value === 'is_null' || this.operatorTarget.value === 'is_not_null') {
      this.toggleNullInput()
    } else {
      this.toggleOriginalInput()
    }
  }

  toggleNullInput () {
    this.hideOriginal()
    this.showNull()
  }

  toggleOriginalInput () {
    this.showOriginal()
    this.hideNull()
  }

  hideOriginal () {
    this.originalTarget.style.display = 'none'
    this.originalTarget.setAttribute('data-filter-target', 'value_original')
  }

  showOriginal () {
    this.originalTarget.style.display = 'block'
    this.originalTarget.setAttribute('data-filter-target', 'value')
  }

  hideNull () {
    this.nullTarget.style.display = 'none'
    this.nullTarget.setAttribute('data-filter-target', 'value_null')
  }

  showNull () {
    this.nullTarget.style.display = 'block'
    this.nullTarget.setAttribute('data-filter-target', 'value')
  }
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
headmin-0.6.1 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.6.0 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.9 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.8 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.7 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.6 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.5 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.4 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.3 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.2 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.1 app/assets/javascripts/headmin/controllers/filter_row_controller.js
headmin-0.5.0 app/assets/javascripts/headmin/controllers/filter_row_controller.js