forked from hotwired/turbo-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As an alternative to building support for Rails' Unobtrusive JavaScript into `@hotwired/turbo` itself, instead publish a `@hotwired/turbo-rails/ujs` file to re-use the existing `@rails/ujs` hooks, and bridge the gaps between new `turbo:`-prefixed and `ajax:`-prefixed events. This is a re-imagining of [hotwired/turbo#40][] and ([hotwired/turbo#384][]). If deemed viable, this work would yield some follow up tasks: * drop support for `[data-turbo-method]` ([hotwired/turbo#277][]) * drop support for `[data-confirm]` ([hotwired/turbo#379][]) [hotwired/turbo#40]: hotwired/turbo#40 [hotwired/turbo#277]: hotwired/turbo#277 [hotwired/turbo#379]: hotwired/turbo#379 [hotwired/turbo#384]:hotwired/turbo#384
- Loading branch information
1 parent
12b0962
commit 4c5899a
Showing
5 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<turbo-frame id="frame"></turbo-frame> | ||
|
||
<h1>a[data-disable-with]</h1> | ||
|
||
<a href="<%= new_message_path(sleep: 0.1) %>" data-disable-with="Page: Visiting">Page: Visit</a> | ||
|
||
<a href="<%= new_message_path(sleep: 0.1) %>" data-turbo-frame="frame" data-disable-with="Frame: Visiting">Frame: Visit</a> | ||
|
||
<hr> | ||
|
||
<h1>form[method="get"]</h1> | ||
|
||
<form> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<button data-disable-with="Submitting GET form button">Submit GET form button</button> | ||
</form> | ||
|
||
<form data-turbo-frame="frame"> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<button data-disable-with="Submitting GET form[data-turbo-frame] button">Submit GET form[data-turbo-frame] button</button> | ||
</form> | ||
|
||
<form> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<input type="submit" value="Submit GET form button[data-turbo-frame]" data-turbo-frame="frame" data-disable-with="Submitting GET form button[data-turbo-frame]"> | ||
</form> | ||
|
||
<form> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<input type="submit" value="Submit GET form input" data-disable-with="Submitting GET form input"> | ||
</form> | ||
|
||
<form data-turbo-frame="frame" | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<input type="submit" value="Submit GET form[data-turbo-frame] input" data-disable-with="Submitting GET form[data-turbo-frame] input"> | ||
</form> | ||
|
||
<form> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<input type="submit" value="Submit GET form input[data-turbo-frame]" data-turbo-frame="frame" data-disable-with="Submitting GET form input[data-turbo-frame]"> | ||
</form> | ||
|
||
<hr> | ||
|
||
<h1>form[method="post"]</h1> | ||
|
||
<%= form_with model: @message do %> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<button data-disable-with="Submitting POST form button">Submit POST form button</button> | ||
<% end %> | ||
|
||
<%= form_with model: @message, data: { turbo_frame: "frame" } do |form| %> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<button data-disable-with="Submitting POST form[data-turbo-frame] button">Submit POST form[data-turbo-frame] button</button> | ||
<% end %> | ||
|
||
<%= form_with model: @message do |form| %> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<input type="submit" value="Submit POST form button[data-turbo-frame]" data-turbo-frame="frame" data-disable-with="Submitting POST form button[data-turbo-frame]"> | ||
<% end %> | ||
|
||
<%= form_with model: @message do %> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<input type="submit" value="Submit POST form input" data-disable-with="Submitting POST form input"> | ||
<% end %> | ||
|
||
<%= form_with model: @message, data: { turbo_frame: "frame" } do |form| %> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<input type="submit" value="Submit POST form[data-turbo-frame] input" data-disable-with="Submitting POST form[data-turbo-frame] input"> | ||
<% end %> | ||
|
||
<%= form_with model: @message do |form| %> | ||
<input type="hidden" name="sleep" value="0.1"> | ||
<input type="submit" value="Submit POST form input[data-turbo-frame]" data-turbo-frame="frame" data-disable-with="Submitting POST form input[data-turbo-frame]"> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
require "application_system_test_case" | ||
|
||
class UjsHTMLAnchorElementTest < ApplicationSystemTestCase | ||
test "supports with a[data-disable-with]" do | ||
visit new_message_path | ||
|
||
click_link "Page: Visit" | ||
|
||
assert_link "Page: Visiting" | ||
assert_link "Frame: Visit" | ||
assert_no_link "Page: Visiting" | ||
end | ||
|
||
test "supports a[data-turbo-frame][data-disable-with]" do | ||
visit new_message_path | ||
|
||
click_link "Frame: Visit" | ||
|
||
assert_link "Frame: Visiting" | ||
assert_link "Frame: Visit" | ||
assert_no_link "Frame: Visiting" | ||
end | ||
end | ||
|
||
class UjsHTMLButtonElementTest < ApplicationSystemTestCase | ||
# test "supports form[method=get] button[data-disable-with]" do | ||
# visit new_message_path | ||
# | ||
# click_button "Page: Submit GET form button" | ||
# | ||
# assert_button "Page: Submitting GET form button", disabled: true | ||
# assert_no_button "Page: Submit GET form button" | ||
# assert_button "Page: Submit GET form button" | ||
# assert_no_button "Page: Submitting GET form button" | ||
# end | ||
# | ||
# test "supports form[method=get][data-turbo-frame] button[data-disable-with]" do | ||
# visit new_message_path | ||
# | ||
# click_button "Frame: Submit GET form[data-turbo-frame] button" | ||
# | ||
# assert_button "Frame: Submitting GET form[data-turbo-frame] button", disabled: true | ||
# assert_no_button "Frame: Submitting GET form[data-turbo-frame] button" | ||
# assert_button "Frame: Submit GET form[data-turbo-frame] button" | ||
# assert_no_button "Frame: Submitting GET form[data-turbo-frame] button" | ||
# end | ||
# | ||
# test "supports form[method=get] button[data-disable-with][data-turbo-frame]" do | ||
# visit new_message_path | ||
# | ||
# click_button "Frame: Submit GET form button[data-turbo-frame]" | ||
# | ||
# assert_button "Frame: Submitting GET form button[data-turbo-frame]", disabled: true | ||
# assert_no_button "Frame: Submitting GET form button[data-turbo-frame]" | ||
# assert_button "Frame: Submitting GET form button[data-turbo-frame]" | ||
# assert_no_button "Frame: Submitting GET form button[data-turbo-frame]" | ||
# end | ||
# | ||
test "supports form[method=post] button[data-disable-with]" do | ||
visit new_message_path | ||
|
||
click_button "Submit POST form button" | ||
|
||
assert_button "Submitting POST form button", disabled: true | ||
assert_button "Submit POST form button" | ||
assert_no_button "Submitting POST form button" | ||
end | ||
|
||
test "supports form[method=post] button[data-turbo-frame][data-disable-with]" do | ||
visit new_message_path | ||
|
||
click_button "Submit POST form button[data-turbo-frame]" | ||
|
||
assert_button "Submitting POST form button[data-turbo-frame]", disabled: true | ||
assert_button "Submit POST form button[data-turbo-frame]" | ||
assert_no_button "Submitting POST form button[data-turbo-frame]" | ||
end | ||
|
||
test "supports form[method=post][data-turbo-frame] button[data-disable-with]" do | ||
visit new_message_path | ||
|
||
click_button "Submit POST form[data-turbo-frame] button" | ||
|
||
assert_button "Submitting POST form[data-turbo-frame] button", disabled: true | ||
assert_button "Submit POST form[data-turbo-frame] button" | ||
assert_no_button "Submitting POST form[data-turbo-frame] button" | ||
end | ||
end | ||
|
||
class UjsHTMLInputElementTest < ApplicationSystemTestCase | ||
# test "supports form[method=get] input[data-disable-with]" do | ||
# visit new_message_path | ||
# | ||
# click_button "Page: Submit GET form input" | ||
# | ||
# assert_button "Page: Submitting GET form input", disabled: true | ||
# assert_no_button "Page: Submit GET form input" | ||
# assert_button "Page: Submit GET form input" | ||
# assert_no_button "Page: Submitting GET form input" | ||
# end | ||
# | ||
# test "supports form[method=get][data-turbo-frame] input[data-disable-with]" do | ||
# visit new_message_path | ||
# | ||
# click_button "Frame: Submit GET form[data-turbo-frame] input" | ||
# | ||
# assert_button "Frame: Submitting GET form input", disabled: true | ||
# assert_no_button "Frame: Submitting GET form[data-turbo-frame] input" | ||
# assert_button "Frame: Submit GET form[data-turbo-frame] input" | ||
# assert_no_button "Frame: Submitting GET form[data-turbo-frame] input" | ||
# end | ||
# | ||
# test "supports form[method=get] input[data-disable-with][data-turbo-frame]" do | ||
# visit new_message_path | ||
# | ||
# click_button "Frame: Submit GET form input[data-turbo-frame]" | ||
# | ||
# assert_button "Frame: Submitting GET form input[data-turbo-frame]", disabled: true | ||
# assert_no_button "Frame: Submitting GET form input[data-turbo-frame]" | ||
# assert_button "Frame: Submitting GET form input[data-turbo-frame]" | ||
# assert_no_button "Frame: Submitting GET form input[data-turbo-frame]" | ||
# end | ||
|
||
test "supports form[method=post] input[data-disable-with]" do | ||
visit new_message_path | ||
|
||
click_button "Submit POST form input" | ||
|
||
assert_button "Submitting POST form input", disabled: true | ||
assert_button "Submit POST form input" | ||
assert_no_button "Submitting POST form input" | ||
end | ||
|
||
test "supports form[method=post] input[data-turbo-frame][data-disable-with]" do | ||
visit new_message_path | ||
|
||
click_button "Submit POST form input[data-turbo-frame]" | ||
|
||
assert_button "Submitting POST form input[data-turbo-frame]", disabled: true | ||
assert_button "Submit POST form input[data-turbo-frame]" | ||
assert_no_button "Submitting POST form input[data-turbo-frame]" | ||
end | ||
|
||
test "supports form[method=post][data-turbo-frame] input[data-disable-with]" do | ||
visit new_message_path | ||
|
||
click_button "Submit POST form[data-turbo-frame] input" | ||
|
||
assert_button "Submitting POST form[data-turbo-frame] input", disabled: true | ||
assert_button "Submit POST form[data-turbo-frame] input" | ||
assert_no_button "Submitting POST form[data-turbo-frame] input" | ||
end | ||
end |