-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Update documentation to lead with ajax param event.detail
#30881
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
browser to submit the form via normal means (i.e. non-Ajax submission) will be | ||
canceled and the form will not be submitted at all. This is useful for | ||
implementing your own Ajax file upload workaround. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this documentation no longer relevant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is relevant. It was moved, not removed, below the table of events:
https://github.com/dimroc/rails/blob/master/guides/source/working_with_javascript_in_rails.md#rails-ujs-event-handlers
| `ajax:error` | xhr, status, err | After completion, if the response was an error. | | ||
| `ajax:complete` | xhr, status | After the request has been completed, no matter the outcome.| | ||
| `ajax:aborted:file` | elements | If there are non-blank file inputs, aborts if stopped. | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were this whole section removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is repeated below with the correct extra parameters here:
https://github.com/dimroc/rails/blob/master/guides/source/working_with_javascript_in_rails.md#rails-ujs-event-handlers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok!! Maybe we should add a link to old version of table for jquery-ujs users?
http://guides.rubyonrails.org/v5.1/working_with_javascript_in_rails.html#dealing-with-ajax-events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. How does having a note mentioning the old jquery-ujs with a link to jquery-ujs wiki sound? https://github.com/rails/jquery-ujs/wiki/ajax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, lets change to that. That used to(is still) the official old events doc.
$("#new_article").append "<p>ERROR</p>" | ||
``` | ||
|
||
Obviously, you'll want to be a bit more sophisticated than that, but it's a | ||
start. | ||
|
||
NOTE: As of Rails 5.1 and the new `rails-ujs`, the parameters `e, data, status, xhr` | ||
have been bundled into `event.detail`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add the same wiki link here as well. e, data, status, xhr
don't mean anything otherwise in future.
|
||
If you stop `ajax:before` or `ajax:beforeSend` by returning false from the | ||
handler method, the Ajax request will never take place. The `ajax:before` event | ||
is also useful for manipulating form data before serialization. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove the is also useful
here.
Alright, I've updated the PR with the suggested feedback. Let me know @vipulnsward @guilleiguaran if we're good to go. |
$("#new_article").append "<p>ERROR</p>" | ||
``` | ||
|
||
Obviously, you'll want to be a bit more sophisticated than that, but it's a | ||
start. | ||
|
||
NOTE: As of Rails 5.1 and the new `rails-ujs`, the parameters `e, data, status, xhr` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the parameters data, status, xhr
not e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -405,6 +377,22 @@ document.body.addEventListener('ajax:success', function(event) { | |||
}) | |||
``` | |||
|
|||
NOTE: As of Rails 5.1 and the new `rails-ujs`, the parameters `e, data, status, xhr` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Fixes issue #30880
Summary
Using
rails-ujs
, notjquery-ujs
The following remote form
= link_to "an article", @article, remote: true
can no longer be handled with the documented javascript as shown here http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html#form-with:
This fixes the documentation and code snippets.