Skip to content

Commit

Permalink
変数名の変更
Browse files Browse the repository at this point in the history
  • Loading branch information
hagiya0121 committed Dec 10, 2024
1 parent 97b19ed commit ba692b1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/javascript/fileinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,29 @@ function initializeDiplomaUploadField() {
const removeFlag = document.getElementById('js-remove-pdf-flag')
const fileName = document.getElementById('js-pdf-name')
const fileInput = uploadField.querySelector('input[type="file"]')
const isFileUploaded = !!fileLink

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

const updateDisplayedFileName = (name = '') => {
const updateDisplayState = (name = '') => {
fileName.textContent = name
const displayedStatus = name ? 'block' : 'none'
fileName.style.display = displayedStatus
removeButton.style.display = displayedStatus
}

removeButton.addEventListener('click', () => {
if (fileLink) fileLink.style.display = 'none'
if (isFileUploaded) fileLink.style.display = 'none'
uploadField.style.display = 'flex'
fileInput.value = ''
removeFlag.value = '1'
updateDisplayedFileName()
updateDisplayState()
})

fileInput.addEventListener('change', () => {
const selectedFile = fileInput.files[0]
updateDisplayedFileName(selectedFile.name)
updateDisplayState(selectedFile.name)
if (selectedFile) removeFlag.value = '0'
})
}
Expand Down

0 comments on commit ba692b1

Please sign in to comment.