Sha256: 91f4847c33047276750fbb2546ed247e36ede2c7d67dbbc769924eca57434c70

Contents?: true

Size: 588 Bytes

Versions: 4

Compression:

Stored size: 588 Bytes

Contents

import ApplicationController from './application_controller'

export default class extends ApplicationController {
  initialize () {
    this.boundHandleKeyDown = this.handleKeyDown.bind(this)
  }

  connect () {
    this.element.addEventListener('keydown', this.boundHandleKeyDown)
  }

  disconnect () {
    this.element.removeEventListener('keydown', this.boundHandleKeyDown)
  }

  handleKeyDown (e) {
    if (e.key === 'Enter' && this.preventEnterKey(e.target)) {
      e.preventDefault()
    }
  }

  preventEnterKey (el) {
    return el.matches('input:not([type="submit"])')
  }
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trestle-0.10.1 frontend/js/controllers/keyboard_submit_controller.js
trestle-0.10.0 frontend/js/controllers/keyboard_submit_controller.js
trestle-0.10.0.pre2 frontend/js/controllers/keyboard_submit_controller.js
trestle-0.10.0.pre frontend/js/controllers/keyboard_submit_controller.js