-
Notifications
You must be signed in to change notification settings - Fork 112
Conditional question fix for removing questions bug rails7 #3516
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
Open
johnpinto1
wants to merge
4
commits into
development
Choose a base branch
from
conditional-question-fix-for-removing-questions-bug-rails7
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
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})`); | ||
|
||
/** | ||
// THIS CODE MAY BE OBSOLETE. | ||
// RETAINING IT TILL SURE. | ||
const heading = progressDiv.closest('.card-heading'); | ||
if (numSecQuestions === 0) { // disable section if empty | ||
if (heading.parent().attr('aria-expanded') === 'true') { | ||
heading.parent().trigger('click'); | ||
} | ||
heading.addClass('empty-section'); | ||
heading.closest('.card').find(`#collapse-${id}`).hide(); | ||
heading.closest('.card').find('i.fa-plus, i.fa-minus').removeClass('fa-plus').removeClass('fa-minus'); | ||
} else if (heading.hasClass('empty-section')) { // enable section if questions re-added | ||
heading.removeClass('empty-section'); | ||
heading.closest('.card').find('i[aria-hidden="true"]').addClass('fa-plus'); | ||
heading.closest('.card').find(`#collapse-${id}`).css('display', ''); | ||
} | ||
*/ | ||
}; | ||
|
||
// 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 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').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(''); | ||
} | ||
|
||
}); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an important PR that fixes a number of lingering bugs. Also, I'm reading the "TODO:" and disabled rubocop offences at the top of this action:
I share the concerns expressed there and worry about the state of this controller action. It suggests creating separate
create
andupdate
actions. Now it looks we are destroying answers withindef create_or_update
as well. I'd like to branch off of this PR and make an attempt at cleaning things up here a bit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if you can simplify.