Skip to content

Commit

Permalink
When creating a quest, new answers and questions are made from clean …
Browse files Browse the repository at this point in the history
…templates.
  • Loading branch information
straumer committed Nov 5, 2019
1 parent e556eb8 commit 797fc1e
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions app/assets/v2/js/pages/quests.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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());
});


Expand Down

0 comments on commit 797fc1e

Please sign in to comment.