Skip to content

Commit

Permalink
変数名とメゾッド名を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
hagiya0121 committed Dec 8, 2024
1 parent 9b55b38 commit 7d82332
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions app/javascript/fileinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,27 @@ function extractField(elements) {
}
}

function initializePdfUploadField() {
function initializeDiplomaUploadField() {
const uploadField = document.getElementById('js-pdf-upload-field')
if (!uploadField) return

const removeButton = document.getElementById('js-remove-pdf-button')
const fileLink = document.getElementById('js-pdf-file-link')
const removeFlag = document.getElementById('js-remove-pdf-flag')
const fileNameDisplay = document.getElementById('js-pdf-name')
const fileName = document.getElementById('js-pdf-name')
const fileInput = uploadField.querySelector('input[type="file"]')

uploadField.style.display = fileLink ? 'none' : 'flex'
removeButton.style.display = fileLink ? 'block' : 'none'

const updateFileNameDisplay = (name = '') => {
const updateDisplayedFileName = (name = '') => {
if (name) {
fileNameDisplay.textContent = name
fileNameDisplay.style.display = 'block'
fileName.textContent = name
fileName.style.display = 'block'
removeButton.style.display = 'block'
} else {
fileNameDisplay.textContent = ''
fileNameDisplay.style.display = 'none'
fileName.textContent = ''
fileName.style.display = 'none'
removeButton.style.display = 'none'
}
}
Expand All @@ -105,16 +105,15 @@ function initializePdfUploadField() {
uploadField.style.display = 'flex'
fileInput.value = ''
removeFlag.value = '1'
updateFileNameDisplay()
updateDisplayedFileName()
})

fileInput.addEventListener('change', () => {
if (fileInput.files && fileInput.files[0]) {
const fileName = fileInput.files[0].name
updateFileNameDisplay(fileName)
updateDisplayedFileName(fileInput.files[0].name)
removeFlag.value = '0'
} else {
updateFileNameDisplay()
updateDisplayedFileName()
}
})
}
Expand All @@ -128,5 +127,5 @@ document.addEventListener('DOMContentLoaded', () => {
})
}
initializeFileInput(document)
initializePdfUploadField()
initializeDiplomaUploadField()
})

0 comments on commit 7d82332

Please sign in to comment.