-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathsectionUpdate.js
More file actions
37 lines (31 loc) · 1.41 KB
/
sectionUpdate.js
File metadata and controls
37 lines (31 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Tinymce } from './tinymce.js';
// update details in section progress panel
export const updateSectionProgress = (id, numSecAnswers, numSecQuestions) => {
const progressDiv = $(`#section-panel-${id}`).find('.section-status');
progressDiv.html(`(${numSecAnswers} / ${numSecQuestions})`);
};
// given a question id find the containing div
// used inconditional questions
export const getQuestionDiv = (id) => $(`#answer-form-${id}`).closest('.question-body');
// Clear an answers for a given question id.
export const deleteAllAnswersForQuestion = (questionid) => {
const editAnswerForm = $(`#answer-form-${questionid}`).find('.form-answer');
editAnswerForm.find('input:checkbox').prop('checked', false);
editAnswerForm.find('input:radio').prop('checked', false);
editAnswerForm.find('option').prop('selected', false);
editAnswerForm.find('input:text').val('');
// Get the TinyMce editor textarea and rest content to ''
const editorAnswerTextAreaId = `answer-text-${questionid}`;
const tinyMceAnswerEditor = Tinymce.findEditorById(editorAnswerTextAreaId);
if (tinyMceAnswerEditor) {
tinyMceAnswerEditor.setContent('');
}
// Date fields in form are input of type="date"
// The editAnswerForm.find('input:date') throws error, so
// we need an alternate way to reset date.
editAnswerForm.find('#answer_text').each ( (el) => {
if($(el).attr('type') === 'date') {
$(el).val('');
}
});
};