Skip to content

Commit

Permalink
lintに対応
Browse files Browse the repository at this point in the history
  • Loading branch information
TakashimaAyaka authored and TakashimaAyaka committed Dec 18, 2022
1 parent 30e24e8 commit ede4dfe
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions app/javascript/survey.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

document.addEventListener('DOMContentLoaded', () => {
const Choices = Array.from(
document.querySelectorAll('.a-toggle-checkbox')
)
const Choices = Array.from(document.querySelectorAll('.a-toggle-checkbox'))

Choices.forEach((choice) => {
choice.addEventListener('click', () => {
const additionalQuestionField = document.getElementsByName(`js-additional_question_${choice.name}`)
if(
const additionalQuestionField = document.getElementsByName(
`js-additional_question_${choice.name}`
)
if (
!choice.classList.contains('js-answer_required_choice') &&
choice.type !== 'checkbox'
) {
) {
additionalQuestionField[0].classList.add('is-hidden')
}
})
Expand All @@ -22,20 +21,30 @@ document.addEventListener('DOMContentLoaded', () => {

answerRequiredChoices.forEach((answerRequiredChoice) => {
answerRequiredChoice.addEventListener('click', () => {
const additionalQuestionField = document.getElementsByName(`js-additional_question_${answerRequiredChoice.name}`)
if(answerRequiredChoice.checked) {
const additionalQuestionField = document.getElementsByName(
`js-additional_question_${answerRequiredChoice.name}`
)
if (answerRequiredChoice.checked) {
additionalQuestionField[0].classList.remove('is-hidden')
} else if(!answerRequiredChoice.checked && answerRequiredChoice.type === 'checkbox') {
const choicesInSameQuestion = document.getElementsByName(answerRequiredChoice.name)
} else if (
!answerRequiredChoice.checked &&
answerRequiredChoice.type === 'checkbox'
) {
const choicesInSameQuestion = document.getElementsByName(
answerRequiredChoice.name
)
const checkBoxStatuses = []
choicesInSameQuestion.forEach((ChoiceInSameQuestion) => {
if (ChoiceInSameQuestion.checked && ChoiceInSameQuestion.classList.contains('js-answer_required_choice')) {
if (
ChoiceInSameQuestion.checked &&
ChoiceInSameQuestion.classList.contains('js-answer_required_choice')
) {
checkBoxStatuses.push(true)
} else {
checkBoxStatuses.push(false)
}
})
if(checkBoxStatuses.includes(true)) {
if (checkBoxStatuses.includes(true)) {
additionalQuestionField[0].classList.remove('is-hidden')
} else {
additionalQuestionField[0].classList.add('is-hidden')
Expand All @@ -44,4 +53,3 @@ document.addEventListener('DOMContentLoaded', () => {
})
})
})

0 comments on commit ede4dfe

Please sign in to comment.