Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Conditional Question removed answers not being deleted from UI and DB. #3467

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

johnpinto1
Copy link
Contributor

@johnpinto1 johnpinto1 commented Nov 11, 2024

In the case of the UI, the answers were just hidden. They would reappear if the conditional question option that removed them was changed. This was not noticed as an issue, because any export of plan would never show the hidden answers.
A user noticed this bug.

Changes:

  • We remove the hidden answers from the UI using javascript function deleteAllAnswersForQuestion() in app/javascript/src/utils/sectionUpdate.js, see
    export const deleteAllAnswersForQuestion = (questionid) => {
    const answerFormDiv = $(`#answer-form-${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').text('');
    // 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('');
    }
    });
    };
  • We delete the persisted answers (that were removed by the conditional question option selected) in the db and persist the change before sending a refreshed list of questions to remove in app/controllers/answers_controller.rb, see https://github.com/DMPRoadmap/roadmap/blob/bfb5d0a75ae8d4d56d67b4ba3b1c595b74b13ea9/app/controllers/answers_controller.rb#L101C6-L130C39
  • Updated the RSpec tests taking into account fact that the Conditional question option mave require removal of questiond in different sections in a phase (i,e, plan tab).

     In the case of a conditional question with answers that removed questions from different sections of a phase, any answers of removed questions were not removed, just hidden. Nor were the removed answers deleted in the database.

        Changes:
        - Fixed the broken functionality.

Rspec tests updated in next commit.
Copy link

1 Warning
⚠️ This PR is too big! Consider breaking it down into smaller PRs.

Generated by 🚫 Danger

@johnpinto1 johnpinto1 force-pushed the fix-for-conditional-question-removed-answers-not-being-deleted branch from bfb5d0a to 5326377 Compare November 11, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant