Summary edit 3 primary input types
This commit is contained in:
parent
bc003eecd1
commit
115fca9009
@ -93,7 +93,7 @@ var saveClickHandler = function(e) {
|
||||
var executeQuery;
|
||||
var questionId = thisEd.find('.button-edit').attr('data-questionid');
|
||||
|
||||
if (thisEd.find('textarea.code-answer')) {
|
||||
if (thisEd.hasClass('live_code-type')) {
|
||||
var htmlAnswer = $(thisEd.find('textarea.code-html')[0]).val();
|
||||
var cssAnswer = $(thisEd.find('textarea.code-css')[0]).val();
|
||||
var jsAnswer = $(thisEd.find('textarea.code-js')[0]).val();
|
||||
@ -102,29 +102,38 @@ var saveClickHandler = function(e) {
|
||||
'css': cssAnswer,
|
||||
'js': jsAnswer
|
||||
}
|
||||
} else if(thisEd.find('input').attr('type')=='radio') {
|
||||
} else if(thisEd.hasClass('radio-type')) {
|
||||
$(thisEd.find('input')).each(function() {
|
||||
if($(this).prop('checked')==true) {
|
||||
data = $(this).val();
|
||||
data = ({
|
||||
'radio': $(this).val()
|
||||
})
|
||||
}
|
||||
});
|
||||
} else if(thisEd.find('input').attr('type')=='checkbox') {
|
||||
} else if(thisEd.hasClass('checkbox-type')) {
|
||||
data = {'checkbox': []};
|
||||
|
||||
$(thisEd.find('input')).each(function() {
|
||||
if($(this).prop('checked')==true) {
|
||||
data.push($(this).val());
|
||||
data.checkbox.push($(this).val());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
data = thisEd.find('textarea').val();
|
||||
data = {'text': thisEd.find('textarea').val()};
|
||||
}
|
||||
if(data == '') {
|
||||
$(thisEd).before('<div class="error">Please select or enter a value.</div>');
|
||||
} else {
|
||||
thisEd.find('textarea:not(.code-answer)').replaceWith('<p class="text-answer answer-container">' + $.trim(thisEd.find('textarea').val()) + '</p>');
|
||||
url = thisEd.closest('form').attr('action');
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/summary",
|
||||
data:{ id: questionId, answer: data},
|
||||
url: url,
|
||||
data: ({
|
||||
'answer': data,
|
||||
'submit': true
|
||||
}),
|
||||
success: function(data){
|
||||
executeQuery = true;
|
||||
//console.log(data);
|
||||
|
@ -22,7 +22,8 @@ class CandidateController < ApplicationController
|
||||
end
|
||||
|
||||
def update_answer
|
||||
qid = prep_status.current_question_id
|
||||
qid = params[:qid] ||= prep_status.current_question_id
|
||||
@answer = prep_answer qid
|
||||
send "process_#{prep_question(qid).input_type}"
|
||||
end
|
||||
|
||||
@ -68,8 +69,8 @@ class CandidateController < ApplicationController
|
||||
)
|
||||
end
|
||||
|
||||
def prep_answer
|
||||
answer_ids = { question_id: answer_params[:question_id], candidate_id: current_candidate.to_i }
|
||||
def prep_answer qid = answer_params[:question_id]
|
||||
answer_ids = { question_id: qid, candidate_id: current_candidate.to_i }
|
||||
answer = Answer.find_or_create_by(answer_ids)
|
||||
answer
|
||||
end
|
||||
@ -89,7 +90,6 @@ class CandidateController < ApplicationController
|
||||
end
|
||||
|
||||
def process_text
|
||||
@answer = prep_answer
|
||||
@answer.update(answer: answer_params[:text],
|
||||
saved: params.key?(:save),
|
||||
submitted: params.key?(:submit))
|
||||
@ -97,7 +97,6 @@ class CandidateController < ApplicationController
|
||||
end
|
||||
|
||||
def process_radio
|
||||
@answer = prep_answer
|
||||
@answer.update(answer: answer_params[:radio],
|
||||
saved: params.key?(:save),
|
||||
submitted: params.key?(:submit))
|
||||
@ -105,7 +104,6 @@ class CandidateController < ApplicationController
|
||||
end
|
||||
|
||||
def process_checkbox
|
||||
@answer = prep_answer
|
||||
@answer.update(answer: answer_params[:checkbox],
|
||||
saved: params.key?(:save),
|
||||
submitted: params.key?(:submit))
|
||||
@ -113,7 +111,6 @@ class CandidateController < ApplicationController
|
||||
end
|
||||
|
||||
def process_live_code
|
||||
@answer = prep_answer
|
||||
@answer.update(answer: answer_params[:live_code].to_h,
|
||||
saved: params.key?(:save),
|
||||
submitted: params.key?(:submit))
|
||||
|
@ -6,7 +6,7 @@
|
||||
</p>
|
||||
|
||||
<% @quiz.each do |question| %>
|
||||
<%= form_for(:answer, url: post_summary_path, html:{id: 'summary-form'}) do |form| %>
|
||||
<%= form_for(:answer, url: post_answer_path(answer_id: question.answer_id, qid: question.question_id), html:{class: 'summary-form'}) do |form| %>
|
||||
<article class="answer-sec <%= question.input_type %>-type" data-qid="<%= question.question_id %>">
|
||||
<div class="question-heading">
|
||||
<div class="question-title">
|
||||
|
Loading…
Reference in New Issue
Block a user