Add politicians question type
This commit is contained in:
parent
4fe218166f
commit
2893f2bc53
16 changed files with 101 additions and 33 deletions
|
@ -1,23 +1,11 @@
|
|||
import debounce from 'debounce'
|
||||
|
||||
const csrfToken = document.querySelector("[name='csrf-token']").content
|
||||
import { submitValueDebounced } from './submit_value.js'
|
||||
|
||||
export default function initSimpleQuestions() {
|
||||
document.querySelectorAll('[data-behaviour="question_simple_input"]').forEach((input) => {
|
||||
const submitUrl = input.dataset.submitUrl
|
||||
const submit = submitValueDebounced()
|
||||
|
||||
const handleInput = debounce(() => {
|
||||
fetch(submitUrl, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
"x-csrf-token": csrfToken,
|
||||
"content-type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ value: input.value }),
|
||||
})
|
||||
}, 300)
|
||||
|
||||
input.addEventListener('change', handleInput)
|
||||
input.addEventListener('input', handleInput)
|
||||
input.addEventListener('change', () => submit(submitUrl, {value: input.value}))
|
||||
input.addEventListener('input', () => submit(submitUrl, {value: input.value}))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue