Skip to content

Commit

Permalink
Improve error messages on review form mistakes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Oct 27, 2020
1 parent 7612e57 commit fea0fd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ function append_field(fid, pos) {
}

function rfs(data) {
var i, fid, $j;
var i, fid, $j, m;
original = data.fields;
samples = data.samples;
stemplate = data.stemplate;
Expand All @@ -496,8 +496,10 @@ function rfs(data) {

// highlight errors, apply request
for (i in data.req || {}) {
if (!$("#" + i).length)
rfs.add(false, i.replace(/^.*_/, ""));
if (!$("#" + i).length
&& (m = i.match(/^(?:rf_|)([st]\d+)(?:|_.*)$/))) {
add_field(m[1]);
}
$j = $("#" + i);
if (!text_eq($j.val(), data.req[i])) {
$j.val(data.req[i]);
Expand Down
5 changes: 3 additions & 2 deletions src/settings/s_reviewform.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private function populate_field($fj, ReviewField $f, SettingValues $sv, $fid) {
} else {
$fj->name = $sn;
}
$error_sn = $sn ? : "<Unnamed field>";

if ($sv->has_reqv("rf_{$fid}_position")) {
$pos = cvtnum($sv->reqv("rf_{$fid}_position"));
Expand Down Expand Up @@ -109,7 +110,7 @@ private function populate_field($fj, ReviewField $f, SettingValues $sv, $fid) {
if ($fj->description === "")
unset($fj->description);
} else if ($pos > 0) {
$sv->error_at("rf_{$fid}_description", htmlspecialchars($sn) . " description: " . $err);
$sv->error_at("rf_{$fid}_description", htmlspecialchars($error_sn) . " description: " . $err);
}
}

Expand All @@ -125,7 +126,7 @@ private function populate_field($fj, ReviewField $f, SettingValues $sv, $fid) {
$ok = $this->check_options($sv, $fid, $fj);
}
if ((!$ok || count($fj->options) < 2) && $pos > 0) {
$sv->error_at("rf_{$fid}_options", htmlspecialchars($sn) . ": Invalid choices.");
$sv->error_at("rf_{$fid}_options", htmlspecialchars($error_sn) . ": Invalid choices.");
if ($this->option_error) {
$sv->error_at(null, $this->option_error);
}
Expand Down

0 comments on commit fea0fd1

Please sign in to comment.