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

Fix callback in rails ujs #29127

Merged
merged 1 commit into from Oct 19, 2017

Conversation

@DmytroVasin
Copy link
Contributor

@DmytroVasin DmytroVasin commented May 17, 2017

Steps to reproduce

Hi!
I'm using rails 5.1.1 and faced with next unexpected behaviour.

According to documentation Ajax request should not happen if I will return false from ajax:before or ajax:beforeSend events:

$('#form').on('ajax:beforeSend', function(event) {
  return false;
});

Even test suits in current Rails version check that. But tests stop at runtime - they just halt.

Tests: call-remote-callback module inside /actionview/test/ujs/test folder.

Expected behavior:

return false inside ajax:beforeSend should prevent request.

Actual behavior:

return false inside ajax:beforeSend does not prevent request.

Furthermore if BeforeSend Return false - send request happens

System configuration

Rails version:
5.1.1
Ruby version:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]

Other Information

In current PR:

If i did something wrong, missed something or remove useful stuff - please let me know.

Thanks!

@rafaelfranca rafaelfranca requested review from guilleiguaran and javan May 17, 2017
@DmytroVasin DmytroVasin force-pushed the DmytroVasin:rails-ujs-remote-callbacks branch 3 times, most recently May 29, 2017
@DmytroVasin DmytroVasin force-pushed the DmytroVasin:rails-ujs-remote-callbacks branch to 19afeaf Jun 7, 2017
@DmytroVasin
Copy link
Contributor Author

@DmytroVasin DmytroVasin commented Jun 9, 2017

Any news on that?

Anyway I simplified PR. Now it contains only fix of callback.

@guilleiguaran guilleiguaran merged commit b7bf709 into rails:master Oct 19, 2017
2 checks passed
2 checks passed
codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@guilleiguaran
Copy link
Member

@guilleiguaran guilleiguaran commented Oct 19, 2017

@DmytroVasin thanks!! I was running UJS tests in a browser and noticed this as an observable bug in the test suite, merging your PR fixed it right away!!

@ta1kt0me
Copy link
Contributor

@ta1kt0me ta1kt0me commented Oct 26, 2017

@guilleiguaran @DmytroVasin Hi, thanks for the fix! I'm looking forward releasing this. Is there any plan to backport this to 5.1.x ?

y-yagi added a commit to y-yagi/rails that referenced this pull request Dec 17, 2017
y-yagi added a commit that referenced this pull request Dec 17, 2017
Fix callback in rails ujs
@obnijnil
Copy link

@obnijnil obnijnil commented Apr 14, 2018

I found return false in both ajax:before and ajax:beforeSend handlers like:

document.querySelector('form').addEventListener('ajax:beforeSend', function(event) {
  return false;
});

doesn't prevent the form request, but event.preventDefault(); does:

document.querySelector('form').addEventListener('ajax:beforeSend', function(event) {
  event.preventDefault();
});

Is it a bug, or am I misuse something?

Rails version: 5.1.4/5.2.0.

@DmytroVasin
Copy link
Contributor Author

@DmytroVasin DmytroVasin commented Apr 14, 2018

@obnijnil Thanks for your comment,
In that PR I tried to provide my thoughts. Please look into it.

Thank you.

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

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.