From 4f2df691ba7eb0ea5d6690a08f1b476f2345c191 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 22 Sep 2016 10:18:21 +0200 Subject: [PATCH] add error validations --- .../experiments/dropdown_actions.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/experiments/dropdown_actions.js b/app/assets/javascripts/experiments/dropdown_actions.js index 82759ee45..eb093b18a 100644 --- a/app/assets/javascripts/experiments/dropdown_actions.js +++ b/app/assets/javascripts/experiments/dropdown_actions.js @@ -17,7 +17,7 @@ }); validateMoveModal(id); clearModal($(id)); - reloadPageAfterUpdate($(id)); + validateExperimentForm($(id)); }) .on("ajax:error", function() { animateSpinner(null, false); @@ -75,13 +75,32 @@ } } // Reload after successfully updated experiment - function reloadPageAfterUpdate(element){ + function validateExperimentForm(element){ if ( element ) { var form = element.find("form"); form .on('ajax:success' , function(){ animateSpinner(form, true); location.reload(); + }) + .on('ajax:error', function(e, error){ + var msg = JSON.parse(error.responseText); + if ( 'name' in msg ) { + renderFormError(e, + element.find("#experiment-name"), + msg.name.toString(), + true); + } else if ( 'description' in msg ) { + renderFormError(e, + element.find("#experiment-description"), + msg.description.toString(), + true); + } else { + renderFormError(e, + element.find("#experiment-name"), + error.statusText, + true); + } }); } }