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

Update documentation to lead with ajax param event.detail #30881

Merged
merged 2 commits into from
Nov 24, 2017

Conversation

dimroc
Copy link
Contributor

@dimroc dimroc commented Oct 13, 2017

Fixes issue #30880

Summary

Using rails-ujs, not jquery-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:

  $("a[data-remote]").on("ajax:success", function(e, data, status, xhr) {
    console.log(data, status, xhr) // undefined
  }));

This fixes the documentation and code snippets.

@rails-bot
Copy link

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.

Copy link
Member

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?

Copy link
Contributor Author

@dimroc dimroc Oct 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| `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. |

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another, more accurate table, exists below. Screenshot:

image

Copy link
Member

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

Copy link
Contributor Author

@dimroc dimroc Oct 22, 2017

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

Copy link
Member

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`.
Copy link
Member

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
Copy link
Member

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.

@dimroc
Copy link
Contributor Author

dimroc commented Nov 23, 2017

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`
Copy link
Member

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

Copy link
Contributor Author

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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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

Successfully merging this pull request may close these issues.

None yet

5 participants