improved error reporting in forms

cpsdqs/unified-input
Ondřej Hruška 7 years ago
parent 58dd0c929f
commit f6ab97a886
  1. 11
      js/appcommon.js

@ -78,18 +78,19 @@ $.ready(function () {
let errAt = location.search.indexOf('err=') let errAt = location.search.indexOf('err=')
if (errAt !== -1 && qs('.Box.errors')) { if (errAt !== -1 && qs('.Box.errors')) {
let errs = location.search.substr(errAt + 4).split(',') let errs = location.search.substr(errAt + 4).split(',')
let hres = [] let humanReadableErrors = []
errs.forEach(function (er) { errs.forEach(function (er) {
let lbl = qs('label[for="' + er + '"]') let lbl = qs('label[for="' + er + '"]')
if (lbl) { if (lbl) {
lbl.classList.add('error') lbl.classList.add('error')
hres.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, '')) humanReadableErrors.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, ''))
} else {
hres.push(er)
} }
// else {
// hres.push(er)
// }
}) })
qs('.Box.errors .list').innerHTML = hres.join(', ') qs('.Box.errors .list').innerHTML = humanReadableErrors.join(', ')
qs('.Box.errors').classList.remove('hidden') qs('.Box.errors').classList.remove('hidden')
} }

Loading…
Cancel
Save