|
| 1 | +import { Tinymce } from './tinymce.js'; |
| 2 | + |
1 | 3 | // update details in section progress panel |
2 | 4 | export const updateSectionProgress = (id, numSecAnswers, numSecQuestions) => { |
3 | 5 | const progressDiv = $(`#section-panel-${id}`).find('.section-status'); |
4 | 6 | progressDiv.html(`(${numSecAnswers} / ${numSecQuestions})`); |
5 | | - |
6 | | - /** |
7 | | - // THIS CODE MAY BE OBSOLETE. |
8 | | - // RETAINING IT TILL SURE. |
9 | | - const heading = progressDiv.closest('.card-heading'); |
10 | | - if (numSecQuestions === 0) { // disable section if empty |
11 | | - if (heading.parent().attr('aria-expanded') === 'true') { |
12 | | - heading.parent().trigger('click'); |
13 | | - } |
14 | | - heading.addClass('empty-section'); |
15 | | - heading.closest('.card').find(`#collapse-${id}`).hide(); |
16 | | - heading.closest('.card').find('i.fa-plus, i.fa-minus').removeClass('fa-plus').removeClass('fa-minus'); |
17 | | - } else if (heading.hasClass('empty-section')) { // enable section if questions re-added |
18 | | - heading.removeClass('empty-section'); |
19 | | - heading.closest('.card').find('i[aria-hidden="true"]').addClass('fa-plus'); |
20 | | - heading.closest('.card').find(`#collapse-${id}`).css('display', ''); |
21 | | - } |
22 | | - */ |
23 | 7 | }; |
24 | 8 |
|
25 | 9 | // given a question id find the containing div |
26 | 10 | // used inconditional questions |
27 | 11 | export const getQuestionDiv = (id) => $(`#answer-form-${id}`).closest('.question-body'); |
| 12 | + |
| 13 | +// Clear an answers for a given question id. |
| 14 | +export const deleteAllAnswersForQuestion = (questionid) => { |
| 15 | + const answerFormDiv = $(`#answer-form-${questionid}`); |
| 16 | + const editAnswerForm = $(`#answer-form-${questionid}`).find('.form-answer'); |
| 17 | + |
| 18 | + editAnswerForm.find('input:checkbox').prop('checked', false); |
| 19 | + editAnswerForm.find('input:radio').prop('checked', false); |
| 20 | + editAnswerForm.find('option').prop('selected', false); |
| 21 | + editAnswerForm.find('input:text').val(''); |
| 22 | + |
| 23 | + // Get the TinyMce editor textarea and rest content to '' |
| 24 | + const editorAnswerTextAreaId = `answer-text-${questionid}`; |
| 25 | + const tinyMceAnswerEditor = Tinymce.findEditorById(editorAnswerTextAreaId); |
| 26 | + if (tinyMceAnswerEditor) { |
| 27 | + tinyMceAnswerEditor.setContent(''); |
| 28 | + } |
| 29 | + // Date fields in form are input of type="date" |
| 30 | + // The editAnswerForm.find('input:date') throws error, so |
| 31 | + // we need an alternate way to reset date. |
| 32 | + editAnswerForm.find('#answer_text').each ( (el) => { |
| 33 | + if($(el).attr('type') === 'date') { |
| 34 | + $(el).val(''); |
| 35 | + } |
| 36 | + |
| 37 | + }); |
| 38 | +}; |
0 commit comments