From de6c03a73bf40173a86dc6751517166866d146e3 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 1 Sep 2016 16:52:42 +0200 Subject: [PATCH] setup experiment modal input validation --- .../javascripts/experiments/dropdown_actions.js | 12 +++++++++++- app/views/experiments/_form.html.erb | 10 ++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/experiments/dropdown_actions.js b/app/assets/javascripts/experiments/dropdown_actions.js index 1034e7284..8b5925df8 100644 --- a/app/assets/javascripts/experiments/dropdown_actions.js +++ b/app/assets/javascripts/experiments/dropdown_actions.js @@ -1,9 +1,10 @@ - (function(){ // Create ajax hook on given 'element', which should return modal with 'id' => // show that modal function initializeModal(element, id){ + + // Initializev new experiment modal listner $(element) .on("ajax:beforeSend", function(){ animateSpinner(); @@ -15,6 +16,7 @@ keyboard: false, }); validateMoveModal(id); + validateExperimentForm(); }) .on("ajax:error", function() { animateSpinner(null, false); @@ -63,6 +65,14 @@ }) .clearFormErrors(); } + // Setup front-end validations for experiment form + function validateExperimentForm(){ + var form = $("#new-experiment-modal").find("form"); + form.on('submit', function(ev){ + textValidator(ev, $('#new-experiment-name'), false); + textValidator(ev, $('#new-experiment-description'), true); + }); + form.clearFormErrors(); } // Initialize no description edit link function initEditNoDescription(){ diff --git a/app/views/experiments/_form.html.erb b/app/views/experiments/_form.html.erb index 29732c85f..ab78ede99 100644 --- a/app/views/experiments/_form.html.erb +++ b/app/views/experiments/_form.html.erb @@ -1,7 +1,11 @@
- <%= form.text_field :name, label: t("experiments.new.name"), autofocus: true, placeholder: t("experiments.new.name_placeholder") %> + <%= form.text_field :name, + label: t("experiments.new.name"), + autofocus: true, + placeholder: t("experiments.new.name_placeholder"), + id: 'new-experiment-name'%>
@@ -9,7 +13,9 @@
- <%= form.text_area :description, label: t('experiments.new.description') %> + <%= form.text_area :description, + label: t('experiments.new.description'), + id: 'new-experiment-description' %>