import { Controller } from '@hotwired/stimulus'; /* * The following line makes this controller "lazy": it won't be downloaded until needed * See https://github.com/symfony/stimulus-bridge#lazy-controllers */ /* stimulusFetch: 'lazy' */ export default class extends Controller { static values = { url: String, title: String, filename: String, mediaType: String, imdbId: String, episodeId: String } download() { console.log(new FormData(document.querySelector('[name="user_media_preferences_form"]')).values()); fetch('/api/download', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: JSON.stringify({ url: this.urlValue, title: this.element.dataset['title'], filename: this.filenameValue, mediaType: this.mediaTypeValue, imdbId: this.imdbIdValue, episodeId: this.episodeIdValue, filter: new FormData(document.querySelector('[name="user_media_preferences_form"]')).values() }) }) .then(res => res.json()) .then(json => { console.log(json) }) } }