Skip to content

Commit

Permalink
Fix auto-check
Browse files Browse the repository at this point in the history
Bugfix for #11 (issue #25)
  • Loading branch information
lezsakdomi committed Sep 22, 2018
1 parent dbd4c21 commit f8a9be3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions assets/views/quiz-form/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ function registerHandlers(document) {

customClick('form[action="update"] input[type=submit]', () => updateData(), false)

handleEvent('*', 'change', () => {
handleEvent('input', 'change', () => {
if (!window.reorderInProgress) {
fs(checkForm())
autoCheck()
}
})
fs(() => checkForm())
autoCheck()

customClick('form[action="new"] input[type=submit]', () => newQuiz(undefined, true))

Expand Down Expand Up @@ -270,6 +270,7 @@ document.addEventListener('DOMContentLoaded', () => {
.map((input) => parseInt(input.value || 0))
.reduce((a, v) => Math.max(a, v), 0)
+ 1
autoCheck()
} else if (tr.previousElementSibling === null || tr.previousElementSibling
.querySelector('input[name$="[order]"]').value === '') {
if (tr.nextElementSibling && tr.nextElementSibling
Expand All @@ -282,6 +283,8 @@ document.addEventListener('DOMContentLoaded', () => {
.forEach((orderInput) => orderInput.value -= shift)

orderInput.value = 1

autoCheck()
}
} else if (insertBefore) {
orderInput.value = insertBefore.querySelector('input[name$="[order]"]').value
Expand Down Expand Up @@ -418,7 +421,7 @@ function reorderStart(trs = document.querySelectorAll('tr')) {

function reorderEnd(trs = document.querySelectorAll('tr')) {
window.reorderInPorgress = false
fs(checkForm())
autoCheck()
if (trs instanceof HTMLElement) {
trs = arguments
}
Expand Down Expand Up @@ -497,6 +500,12 @@ function newQuiz(data = gatherData(), handleResult = false) {
return promise
}

function autoCheck() {
if (document.querySelector('form').getAttribute('action') === 'check') {
fs(() => checkForm())
}
}

function checkForm(force = false) {
const form = document.querySelector('form')
// noinspection JSCheckFunctionSignatures
Expand Down
2 changes: 1 addition & 1 deletion modules/quizzes-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ router.post('/new', async (req, res, next) => {
const quizRouter = express.Router({})

// noinspection JSUnresolvedFunction
router.use('/:qid', async (req, res, next) => {
router.use('/:qid([0-fA-F]{24}|[\0-\255]{12})', async (req, res, next) => {
// noinspection JSUnresolvedVariable
debug('Fetching quiz \'%s\'...', req.params.qid)
try {
Expand Down

0 comments on commit f8a9be3

Please sign in to comment.