Commit d0ee85be authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

When the error is for a hidden form field, show that in the general

error location. This closes issue #292.
parent 3cc53d0d
......@@ -119,7 +119,8 @@ $(function () {
}
/*
* Add errors to form
* Add errors to form. Watch for errors that are not associated
* with a visible form field, convert to a general error below.
*/
function GenerateFormErrors(form, errors) {
$(form).find(".format-me").each(function () {
......@@ -136,14 +137,18 @@ $(function () {
'</label>';
$(this).parent().append(html);
delete errors[key];
}
}
});
if (!errors || Object.keys(errors).length == 0) {
return;
}
/*
* Deal with a "general" error. Some of the forms have a specific
* spot for this.
*/
if (errors && _.has(errors, "error")) {
if (_.has(errors, "error")) {
if ($('#general_error').length) {
$('#general_error').html(_.escape(errors["error"]));
}
......@@ -152,6 +157,19 @@ $(function () {
alert(errors["error"]);
}
}
else {
var field = Object.keys(errors)[0];
var error = errors[field];
if ($('#general_error').length) {
$('#general_error').html(_.escape(field + ": " + error));
}
else {
console.info("Form error: " + errors["error"]);
alert(errors["error"]);
}
}
}
/*
......
......@@ -209,7 +209,11 @@
</div>
<% } %>
<div class='panel-body'>
<span id="general_error" style="color:red;"></span>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<span id="general_error" style="color:red;"></span>
</div>
</div>
<form id='quickvm_create_profile_form'
class='form-horizontal' role='form'
data-format="wide">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment