TrestleAdmin/trestle

View on GitHub
frontend/js/controllers/keyboard_submit_controller.js

Summary

Maintainability
A
0 mins
Test Coverage
import ApplicationController from './application_controller'

export default class extends ApplicationController {
  connect () {
    this.appendAction('keydown', 'handleKeyDown')
  }

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

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