Commit Graph

24 Commits

Author SHA1 Message Date
Jonathan Hefner
701e17b910 Fix submit button selector for type-less buttons
Follow-up to #48290.

The `:is(button, input)[type='submit']` selector does not match `button`
elements that omit the `type` attribute in favor relying on its default
value (which is `"submit"`).

Co-authored-by: Javan Makhmali <javan@javan.us>
2023-11-24 15:36:13 -06:00
Marc Köhlbrugge
a1504f457c Support nested elements inside <button>
This change is necessary to address a potential issue that could arise when a button or an input of type submit contains child elements, such as spans, icons, or other HTML elements.

Currently, ActiveStorage's `didClick` event listener checks the target of the click event to determine if a submit button was clicked. The target property of the event refers to the specific HTML element that was clicked.

In cases where a submit button contains child elements, and one of these child elements is the element that actually gets clicked, the target would refer to this child element, not the button itself.

Since the `didClick` function checks if the target is a button or an input of type submit, this check would fail, and the button wouldn't be stored in `submitButtonsByForm`.

As a result, if the form is then submitted after a direct upload, the first submit button in the form could be incorrectly used to submit the form, even if a different button was originally clicked. This could cause unexpected behavior, as different submit buttons might be intended to trigger different actions on form submission.

By using the `event.currentTarget` instead, we'll get back the button or an input of type submit. This way we ensure that the correct button is stored in `submitButtonsByForm`, even if the click event was triggered by a child element of the button. This addresses the issue and ensures that the correct button is used to submit the form after a direct upload.

https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
2023-11-13 19:33:53 +00:00
Jonathan Hefner
4dcd6ba8d3 Update .gitattributes for generated JavaScript [ci-skip]
This adds `linguist-generated` and `linguist-vendored` attributes where
appropriate to suppress the files in diffs and exclude the files from
the project's language stats on GitHub.

See https://github.com/github/linguist for more information.
2023-11-05 15:48:08 -06:00
Radamés Roriz
a37f1d4f26
fix: add compiled js from activestorage 2023-03-26 17:05:10 -03:00
Gannon McGibbon
aaa64687e8
Revert #38957 (#44287)
* Revert "Pass service_name param to DirectUploadsController"

This reverts commit 193289dbbe146c56ec16faf8dd1a2c88611feb83.

* Revert "Multi-service direct uploads in Action Text attachment uploads"

This reverts commit 0b69ad4de6ef89c285833a90dd23db25cad7b669.
2022-01-29 14:27:45 +01:00
Nando Vieira
865a01d87c
Export assets. 2022-01-06 13:51:46 -08:00
DmitryTsepelev
193289dbbe Support direct uploads to multiple services 2021-11-14 11:49:06 +03:00
David Heinemeier Hansson
6c96e1cd7b
Move Active Storage JS to ESM and drop Babel transpiling (#42895)
* Move to ESM and drop Babel transpiling

* Make the activestorage JS directly available through the asset pipeline as a precompiled asset

* Use example with direct attachment

* Explain that direct reference is possible

* Active Storage JS is a module

* Retain umd asset for backwards compatibility, add ESM file in addition

* Explain how to use activestorage.esm with importmap

* Use untranspiled activestorage inclusion

* Don't repeat terser options
2021-07-28 15:17:13 -04:00
Sean Doyle
e75b0094d0 ActiveStorage: Pass useCapture to UJS listener
Closes [@hotwired/turbo#243][].

Set the `useCapture` parameter of [addEventListener][] to `true` so that
cancelling the event occurs early enough in the process so that the
resulting upload is cancelled.

[@hotwired/turbo#243]: https://github.com/hotwired/turbo/issues/243#issuecomment-818792129
[addEventListener]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#parameters

Co-authored-by: Javan Makhmali <javan@basecamp.com>
2021-04-13 11:56:01 -04:00
Jonathan Hefner
fd3fd618f4 Add gitattributes for vendored and generated files [ci-skip]
The `linguist-vendored` attribute excludes the specified file from the
project's language stats on GitHub.  The `linguist-generated` attribute
does the same, and also suppresses that file in diffs on GitHub.

See https://github.com/github/linguist for more information.
2020-10-04 16:44:37 -05:00
Nick Weiland
1d133e8a47 Defaults content_type to application/octet-stream
Defaults content_type to application/octet-stream in blob_record.js

[direct_upload_xls_in_chrome]
2020-01-07 10:30:56 -08:00
Cameron Bothner
372dda2a29 Don’t include an undefined X-CSRF-Token header
If there is not a `csrf-token` meta tag in the document, the blob record
XHR was including an `X-CSRF-Token` header set to the string
"undefined." Instead of setting it to undefined, it should not be
included in the absence of a meta tag.
2018-12-27 12:44:19 -05:00
Tasos Maschalidis
d6fcc419fe ASt direct uploads: account for <button type="submit"> elements 2018-11-24 14:54:05 -05:00
bogdanvlviv
0e77706dc5
activestorage: yarn build
Context https://github.com/rails/rails/pull/33413#issuecomment-414137587
2018-08-19 19:33:16 +03:00
Chris Seelus
880f977925 Enable multiple submit buttons for Active Storage forms 2018-08-18 19:31:39 +02:00
George Claghorn
195463736c Fix directly uploading zero-byte files
Closes #33450.
2018-07-27 00:11:22 -04:00
Javan Makhmali
56fc1f812a Unminify activestorage.js 2018-04-25 08:46:56 -05:00
kylekeesling
a7cdad8d26
fixes a bug in IE11 that broke direct uploads 2018-04-06 10:20:25 -04:00
George Claghorn
f008562dd3 Rebuild activestorage.js 2018-02-28 14:10:51 -05:00
George Claghorn
e0867b3672 Clear Blob's type before sending it
Prevent older versions of Chrome from appending a Content-Type header containing the Blob type, rendering the request invalid if we intend not to provide a Content-Type. This behavior was observed in Chrome 58.
2018-02-26 17:20:55 -05:00
Javan Makhmali
f17137b0a1 Rebuild activestorage.js
To pick up 21417e02e906f6b64f013aafefdc0cb8ea8b5e74
2018-01-08 17:13:18 -05:00
Javan Makhmali
1a5bf01fe0 Active Storage: Fix direct uploads in IE 11
Fixes #31531
Closes #31540
2017-12-23 11:21:54 -05:00
_N_I_X_O_N_
c06b614c12 Fix activestorage direct upload on firefox
Direct upload on firefox is not working because it can’t handle click
events on “input[type=submit]”.
After a successful upload we can see on console a xml parse error, it
happens because AWS S3 success body response is empty, so changing the
reponseType suppress this error.
2017-09-12 18:45:23 +00:00
Rafael Mendonça França
9330d01ada Add 'activestorage/' from commit '3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58'
git-subtree-dir: activestorage
git-subtree-mainline: 0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6
git-subtree-split: 3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58
2017-07-31 15:21:22 -04:00