File uploads in IHP seems to behave quite differently in a formFor without JS compared to formForWithoutJavascript.
I wanted to try to perform file uploads without JS as I figured there are parts of my apps that might be better off without Turbolinks and Morphdom.
I have created a Gitpod demonstrating the problem with a simple File record in the database: https://olive-bonobo-8tmc7rr9.ws-eu25.gitpod.io/
Also repo in case that works better: https://github.com/kodeFant/file-upload-nojs
In Web/View/Files/New.hs, we have a standard form with file uploads and a preview and this seems to work well.
renderForm :: File -> Html
renderForm file = formForWithoutJavascript file [hsx|
<input
type="file"
name="fileUrl"
class="form-control-file"
accept="image/*"
data-preview="#fileUrlPreview"
/>
<img id="fileUrlPreview"/>
{submitButton}
|]
The upload action does not behave as I expect. The filename is saved in the record, but without a path. And putStrLn $ show fileUrl prints Nothing, so it seems like the file itself is not picked up.
action CreateFileAction = do
let file = newRecord @File
let fileUrl = fileOrNothing "fileUrl"
putStrLn $ show fileUrl
file
|> buildFile
|> ifValid \case
Left file -> render NewView { .. }
Right file -> do
file <- file |> createRecord
setSuccessMessage "File created"
redirectTo FilesAction
Is this fixable in js-less forms or is it only supported with Turbolinks/Morphdom?