rubyforgood/casa

View on GitHub
app/javascript/src/reports.js

Summary

Maintainability
A
0 mins
Test Coverage
document.addEventListener('DOMContentLoaded', () => {
  document.addEventListener('click', (event) => {
    if (event.target.matches('.report-form-submit')) {
      return handleReportFormSubmit(event)
    }
  })
})

const handleReportFormSubmit = (event) => {
  event.preventDefault()

  const buttonText = event.target.innerHTML

  event.target.disabled = 'disabled'
  event.target.innerHTML = event.target.dataset.disableWith
  event.target.form.submit()

  setTimeout(() => {
    event.target.disabled = false
    event.target.innerHTML = buttonText
  }, 3000)
}