rabbibotton / clog

CLOG - The Common Lisp Omnificent GUI
Other
1.48k stars 101 forks source link

Javascript upload fails by unknown reason #292

Closed ebrasca closed 3 months ago

ebrasca commented 11 months ago

Here the code I try to use, I tried to debug it but I can't see any reason why it fails. It seems the function bound to "/upload" does not get executed when called from JavaScript. Uploading with :method :post :action "/upload" does work fine but I can't manage to make the JavaScript one work. Thank you for your time!

(defun on-upload (clog-body body)
  (declare (ignore clog-body))
  (setf (inner-html body) "")
  (with-clog-create body
      (div (:bind upload)
           (form (:bind u-form
                  :encoding "multipart/form-data")
                 (legend (:content "Upload post"))
                 (form-element (:bind u-finput :file :name "filename" :html-id "uFinput"))
                 (form-element (:submit))))
    (setf (multiplep u-finput) t)
    (debug-mode u-form)
    (clog::set-event u-form "submit"
                     (lambda (data)
                       (declare (ignore data)))
                     :cancel-event t
                     :eval-script (ps:ps
                                    (ps:chain event (prevent-default))
                                    (let ((data-form (ps:new (*form-data))))
                                      (loop :for file :across (ps:chain document (get-element-by-id "uFinput") files)
                                            :do (ps:chain data-form (append "file" file)))
                                      ;; (ps:delete (ps:chain options headers "Content-Type"))
                                      (ps:chain console (log fetch "/upload" (ps:create method "POST" body data-form))))))))
rabbibotton commented 5 months ago

Not sure I understand what you are trying to accomplish here and why using set-event? (sorry for the delay getting to this)

ebrasca commented 5 months ago

No reloading of the page when uploading files!

rabbibotton commented 5 months ago

Trying setting :method in create-form