GithubHelp home page GithubHelp logo

marinosoftware / active_storage_drag_and_drop Goto Github PK

View Code? Open in Web Editor NEW
92.0 92.0 14.0 1.54 MB

Provides a form helper to make it easy to make drag-and-drop file upload fields that work with Rails' Active Storage.

License: MIT License

Ruby 43.49% CSS 2.63% JavaScript 48.28% HTML 5.46% Shell 0.14%

active_storage_drag_and_drop's People

Contributors

daveokeeffe avatar dependabot[bot] avatar iangrantmarino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

active_storage_drag_and_drop's Issues

Upload without form submit

Hi,

I'm trying to trigger file uploads as soon as they're dropped into the dndzone, and I'm just not succeeding. I'm hoping you can help. I'm sure I'm just misunderstanding something. Here's my code:

const form = document.getElementsByClassName('form-with-dnd');

function TriggerProcessUploadQueue(form, event) {
    console.log(event.detail);

    //Start the upload

    let callback = function(error) {
        if (error) {
            console.log('An error was found:');
            console.log(error);
            console.log('This upload will be aborted');
        } else {
            console.log("No errors were detected with this item");
            console.log("Let's upload it now...");
        }
    };

    const uploadEvent = document.createEvent('Event');
    uploadEvent.initEvent('dnd-uploads:process-upload-queue', true, true);
    uploadEvent.detail = { callback };
    form.dispatchEvent(uploadEvent);
}

document.addEventListener('dnd-upload:initialize', function (event) {
    console.log('This item was dropped on the box, or selected from dialog:');
    TriggerProcessUploadQueue(form[0], event);
});

When I step through the code in Chrome Dev Tools I find that the file is present in the detail attribute of event (demonstrated by console.log(event.detail)) but at the below block of code in ujs.js, the nextUpload.current_uploaders.length is equal to 0:

function processUploadQueue (event) {
  const form = event.target
  const { callback } = event.detail
  const nextUpload = new UploadQueueProcessor(form)
  if (nextUpload.current_uploaders.length > 0) {
    nextUpload.start(error => {
      if (error) {
        callback(error)
      } else {
        callback()
      }
    })
  } else {
    callback()
  }
}

I can confirm the form being passed to UploadQueueProcessor is the correct form DOM element.

I'm certain I must be overlooking something obvious, as it all seems to tie together nicely!

Uncaught Error: Can only initialize form controller with a form element.

Getting the above-mentioned error when I try to use active storage drag and drop inside a bootstrap modal via the javascript implementation for rendering. However, using the pure html implementation of the bootstrap modal seems to work fine. Need some help regarding the implementation.

Weird issue that comes up with cocoon nested fields

When I remove an attachment & then save the record; I cannot add anymore attachments to the cocoon field. The file doesn't save the second time around. I don't know exactly why that is happening. Can you please look into it?

Invalid Authenticity Token when using in remote form

Hi, thank you for this great gem. I was having an issue when submitting a remote rails form along with drag_and_drop_file_field

  1. Steps to reproduce
    Create rails form with remote set to true, add <%=f.drag_and_drop_file_field :documents, 'Drag and drop images here!'%> as form field. Submit form.
  2. Expected behaviour
    Submitting form not receiving CSRF error and processing request as js
  3. Actual behaviour
    Submitting form returns 'Can't verify CSRF token authenticity.' error and processing request as html
  4. System configuration
    Rails version: 'Rails 5.2.3'
    Ruby version: 'ruby 2.6.3p62'

Unable to upload new files in edit action with Cocoon

When I remove an attachment & then save the record; I cannot add anymore attachments to the cocoon field. The file doesn't save the second time around. I don't know exactly why that is happening. Can you please look into it?

Title attribute on error not populated on validation error

Hi!

When I set the accept or file_size option, the validation of the selected file works fine, but I see in the DOM that there is a class added to the direct-upload container, direct-upload--error and that a Title with a explanation is set. Unfortunately, the title has the text: TypeError: Error.captureStackTrace is not a function. This does not seem right. Could you have a look?

Doesn't play nice with Turbolinks?

First off thanks for this library!

Looks like the JS for this library assumes the target element is already present on the page, at the time application.js is executed -- however this doesn't work with Turbolinks as application.js will only get executed on the very first request, and so if the dnd-target is not present until a later navigation, the library doesn't get activated.

Worse so, since the start status is cached, even attempts to force-call start() to bind after a turbolinks:load doesn't work.

Would be great to get some better Turbolinks integration given its been the default in Rails 5 and up...

Droped file not showing

Hi I try to use your gem in a rails 7 project,
when I drop the files in the drop zone, they are not listed in the box... but they are there because if I save the files are linked with the new created object.

Do you have any clue for me?

Uploading bar doesn't work

Before or after i click to submit my form, loading bar doesn't fill up. Most scarry part is when i click submit. My cloud storage makes a url place for it but doesn't upload there. Form gets unresponsive and stuck on same page

Persist on form rerender

Is the file_field supposed to persist on a form rerender, for example when any validation for the form object fails and the form gets redisplayed?

Direct uploads?

Does this automatically handle direct uploads: true? or is there a way to set it?

Rails 6 support

Want to use this gem with Rails 6 but unable to do so as current version is dependent on rails (~> 5.2.2.1)

Any idea if there are plans to upgrade?

Two or more similar block gone wrong

I has 5 similar forms in one page, each has 1 drag_and_drop_file_field. when attach is selected their labels appear only at first form, but attach is correctly upload.
perhaps, cause they all have identical ID on input field and ignore html_input options

Would like to improve keyboard accessibility

I noticed the browser file upload starts on clicking the drag-drop box.

I would like to open this file upload box with a keyboard after tabbing to the box. I was not on the best way to do this though.

style placeholder attachments when validation failed - event 'dnd-upload:placeholder' not firing

hi thank you for this gem. I know this is explained in the doc but i am having some trouble. i had a quick question regarding how the flow works when user submits a form that is invalid which is returned with validation errors. I see acdd saves the attachments previously uploaded but not saved to database yet which is great. But i want to be able to style how these look. I was able to do style when they first upload with paintUploadIcon. But when the page re-renders with errors that event does not fire. I also tried document.addEventListener('dnd-upload:placeholder', function (event) { debugger event.preventDefault() }) but this does not fire when the page re-renders. Also when the placeholder attachments are added i cant seem to click the X icon to remove the attachment. Any help would be greatly appreciated.

Adding css to yarn version and removing the need to install the gem

Could I suggest adding the css to the yarn version and removing the need to install the gem all together? Currently, I have copied the css file from the git repo because I have moved away from using the assets pipeline and am using webpack to serve all my assets. With that said, I am still forced to bundle the gem version to handle a few ruby dependencies.

I am really loving this gem. Great job.
Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.