Sha256: 9f7131cd70d3877bded03c11648e95b5daa3ef787334c16b084c92d6d61ef7af

Contents?: true

Size: 847 Bytes

Versions: 2

Compression:

Stored size: 847 Bytes

Contents

function post(path, params, method = 'post') {

  // The rest of this code assumes you are not using a library.
  // It can be made less verbose if you use one.
  const form = document.createElement('form')
  form.method = method
  form.action = path

  for (const key in params) {
    if (params.hasOwnProperty(key)) {
      const hiddenField = document.createElement('input')
      hiddenField.type = 'hidden'
      hiddenField.name = key
      hiddenField.value = params[key]

      form.appendChild(hiddenField)
    }
  }

  document.body.appendChild(form)
  form.submit()
}

function addFilterToSubmit() {
  var form = document.querySelector('form')

  form.onsubmit = function (e) {
    e.preventDefault()
    var formData = new FormData(form)
    var revisedData = getFormDataPacked(formData)
    return post(form.action, revisedData)
  }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
works_cited-0.1.16 app/assets/javascripts/works_cited/submitForm.js
works_cited-0.1.15 app/assets/javascripts/works_cited/submitForm.js