Skip to content

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).

@johnpinto1 johnpinto1 self-assigned this Nov 11, 2024
@github-actions
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
John Pinto added 2 commits December 2, 2024 18:06
     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.
@johnpinto1 johnpinto1 force-pushed the fix-for-conditional-question-removed-answers-not-being-deleted branch from 5326377 to e9c5700 Compare December 2, 2024 18:15
@johnpinto1
Copy link
Contributor Author

@aaronskiba & @benjaminfaure I rebased with your Rails 7 development code,

@johnpinto1 johnpinto1 closed this Jan 31, 2025
@johnpinto1 johnpinto1 deleted the fix-for-conditional-question-removed-answers-not-being-deleted branch January 31, 2025 11:43
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.

2 participants