Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit form after clicked on "add" button #104

Closed
GuillaumeOcculy opened this issue Apr 25, 2022 · 2 comments
Closed

Submit form after clicked on "add" button #104

GuillaumeOcculy opened this issue Apr 25, 2022 · 2 comments
Labels

Comments

@GuillaumeOcculy
Copy link
Contributor

rails (7.0.2.3) uploadcare-rails (2.1.0) importmap-rails (1.0.1)

Is there a way to submit the form after clicked on "add" button ?
Screenshot 2022-04-26 at 00 36 42

Right now I have to click on "add" and then click on my :submit button

# app/models/uploadcare_document.rb
class UploadcareDocument < ApplicationRecord
  mount_uploadcare_file_group :attachments
end

# app/views/uploadcare_documents/_form.html.erb
<%= simple_form_for uploadcare_document do |f| %>
  <%= uploadcare_uploader_field :uploadcare_document, :attachments %>
  <%= f.button  :submit %>
<% end %>
uploadcare.mp4
@optlsnd
Copy link

optlsnd commented Apr 26, 2022

Hi @GuillaumeOcculy,

This is what you can achieve with some JS.

const uploader = uploadcare.Widget("[role=uploadcare-uploader]");
const form = document.getElementById("your-form-identifier");
uploader.onUploadComplete(function () {
  form.submit();
});

Instead of submitting the form right away after a click on the Add button, it's better to wait until all files are uploaded. If you still want to submit the form immediately, replace the onUploadComplete method with onChange.

@GuillaumeOcculy
Copy link
Contributor Author

Thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants