From 797fc1ea47904a2811d1fa62a3059115fc53023d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=ADas=20Ragnarsson?= Date: Wed, 30 Oct 2019 16:38:00 -0500 Subject: [PATCH] When creating a quest, new answers and questions are made from clean templates. --- app/assets/v2/js/pages/quests.new.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/app/assets/v2/js/pages/quests.new.js b/app/assets/v2/js/pages/quests.new.js index f43e39affbe..ee8cd37d905 100644 --- a/app/assets/v2/js/pages/quests.new.js +++ b/app/assets/v2/js/pages/quests.new.js @@ -2,6 +2,8 @@ $(document).ready(function() { const QUESTIONS_LIMIT = 6; const ANSWERS_LIMIT = 10; + const question_template = $('.form-group.question:last').clone(); + const answer_template = question_template.children('span:last').clone(); $(document).on('form#newkudos', 'submit', function(e) { // e.preventDefault(); @@ -18,13 +20,9 @@ $(document).ready(function() { return; } - var dupe_me = $(this).parents('.form-group').find('span:last'); - var clone = dupe_me.clone(); + var last_answer = $(this).parents('.form-group.question').children('span:last'); - // Clean element copied - clone.find('input').val(''); - clone.find('option').attr('selected', false); - dupe_me.after(clone); + last_answer.after(answer_template.clone()); }); $(document).on('click', '.new_quest_background', function(e) { e.preventDefault(); @@ -38,18 +36,15 @@ $(document).ready(function() { $(document).on('click', '.add_question', function(e) { e.preventDefault(); + if ($('.form-group.question').length > QUESTIONS_LIMIT) { - alert('Questions limit exceed'); + alert('The number of questions are limited to ' + QUESTIONS_LIMIT); return; } - var dupe_me = $('.form-group.question:last'); - var clone = dupe_me.clone(); + var last_question = $('.form-group.question:last'); - // Clean element copied - clone.find('input').val(''); - clone.find('option').attr('selected', false); - dupe_me.after(clone); + last_question.after(question_template.clone()); });