mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Submit image when selected
This could have been done with a tiny amount of inline JS, but I went this way in case I needed any special logic for UJS. It turns out we don't.. but it still looks a bit cleaner this way.
This commit is contained in:
@@ -5,12 +5,11 @@
|
||||
|
||||
-# Submit to controller, because StimulusReflex doesn't support file uploads
|
||||
= form_for [:admin, product, image], url: admin_product_image_path(product, image),
|
||||
html: { multipart: true } do |f|
|
||||
html: { multipart: true }, data: { controller: "form" } do |f|
|
||||
%input{ type: :hidden, name: :return_url, value: return_url}
|
||||
= f.hidden_field :viewable_id, value: product.id
|
||||
|
||||
%p
|
||||
-# label.button provides a handy shortcut to open the file selector on click. Unfortunately this trick isn't keyboard accessible though..
|
||||
= f.label :attachment, t(".upload"), class: "button primary icon-upload-alt"
|
||||
= f.file_field :attachment, style: "display: none"
|
||||
= f.submit # todo: submit automatically
|
||||
= f.file_field :attachment, style: "display: none", "data-action": "change->form#submit"
|
||||
|
||||
7
app/webpacker/controllers/form_controller.js
Normal file
7
app/webpacker/controllers/form_controller.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Controller } from "stimulus";
|
||||
|
||||
export default class FormController extends Controller {
|
||||
submit() {
|
||||
this.element.submit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user