Sha256: 202ea35712f7fa9a27d0a25703526a16c7598102067ed124e12d5f7de03d98d5
Contents?: true
Size: 1.41 KB
Versions: 3
Compression:
Stored size: 1.41 KB
Contents
import { Controller } from "@hotwired/stimulus" export default class extends Controller { start(event) { const file = event.detail.file if (!file) return const trixId = event.detail.trixId this.trixTargetId = trixId // DataTransfer() avoids the "TypeError: Failed to set the 'files' property on 'HTMLInputElement': Failed to convert // value to 'FileList'." error which occurs if you try to directly assign: `this.fileField.files = [file]` // https://stackoverflow.com/questions/52078853/is-it-possible-to-update-filelist const fileList = new DataTransfer() fileList.items.add(file) this.fileField.files = fileList.files const changeEvent = new Event("input"); // This triggers the upload this.fileField.dispatchEvent(changeEvent); } get fileField() { return this.element.querySelector('form input.image-upload-file-field') } get form() { return this.element.querySelector('form') } get trixTargetId() { return this.element.querySelector('form > #trix_target_id').value } set trixTargetId(value) { this.element.querySelector('form > #trix_target_id').value = value } #imageData(imageMeta) { return { filename: imageMeta.dataset.filename, signedBlobId: imageMeta.dataset.signedBlobId, imageId: imageMeta.dataset.imageId, embeddedUrl: imageMeta.dataset.embeddedUrl, thumbnail: imageMeta.dataset.thumbnail } } }
Version data entries
3 entries across 3 versions & 1 rubygems