From: Anton Khorev Date: Sat, 3 Aug 2024 00:41:43 +0000 (+0300) Subject: Change richtext edit/preview buttons type to non-submit X-Git-Tag: live~327^2~2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/2ba7eab67da95f75f98c5e20b61f85639af903a9 Change richtext edit/preview buttons type to non-submit --- diff --git a/app/assets/javascripts/richtext.js b/app/assets/javascripts/richtext.js index 3036f169b..70909243b 100644 --- a/app/assets/javascripts/richtext.js +++ b/app/assets/javascripts/richtext.js @@ -21,7 +21,7 @@ $(document).ready(function () { * Install a click handler to switch to edit mode when the * edit button is pressed. */ - $(".richtext_doedit").click(function (event) { + $(".richtext_doedit").click(function () { var editor = $(this).parents(".richtext_container").find("textarea"); var preview = $(this).parents(".richtext_container").find(".richtext_preview"); @@ -30,15 +30,13 @@ $(document).ready(function () { $(this).siblings(".richtext_dopreview").prop("disabled", false); $(this).prop("disabled", true); - - event.preventDefault(); }); /* * Install a click handler to switch to preview mode when the * preview button is pressed. */ - $(".richtext_dopreview").click(function (event) { + $(".richtext_dopreview").click(function () { var editor = $(this).parents(".richtext_container").find("textarea"); var preview = $(this).parents(".richtext_container").find(".richtext_preview"); var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height(); @@ -60,7 +58,5 @@ $(document).ready(function () { $(this).siblings(".richtext_doedit").prop("disabled", false); $(this).prop("disabled", true); - - event.preventDefault(); }); }); diff --git a/app/views/shared/_richtext_field.html.erb b/app/views/shared/_richtext_field.html.erb index f471cbbbf..6f5b6d3d9 100644 --- a/app/views/shared/_richtext_field.html.erb +++ b/app/views/shared/_richtext_field.html.erb @@ -7,8 +7,8 @@
<%= render :partial => "shared/#{type}_help" %> - <%= submit_tag t(".edit"), :id => "#{id}_doedit", :class => "richtext_doedit btn btn-primary", :disabled => true %> - <%= submit_tag t(".preview"), :id => "#{id}_dopreview", :class => "richtext_dopreview btn btn-primary" %> + <%= button_tag t(".edit"), :type => "button", :id => "#{id}_doedit", :class => "richtext_doedit btn btn-primary", :disabled => true %> + <%= button_tag t(".preview"), :type => "button", :id => "#{id}_dopreview", :class => "richtext_dopreview btn btn-primary" %>
diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index bb6c25781..24475fc80 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -119,9 +119,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1 assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1 assert_select "input[name=commit][type=submit][value=Publish]", :count => 1 - assert_select "input[name=commit][type=submit][value=Edit]", :count => 1 - assert_select "input[name=commit][type=submit][value=Preview]", :count => 1 - assert_select "input", :count => 6 + assert_select "button[type=button]", :text => "Edit", :count => 1 + assert_select "button[type=button]", :text => "Preview", :count => 1 + assert_select "input", :count => 4 end end end @@ -272,9 +272,9 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1 assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1 assert_select "input[name=commit][type=submit][value=Update]", :count => 1 - assert_select "input[name=commit][type=submit][value=Edit]", :count => 1 - assert_select "input[name=commit][type=submit][value=Preview]", :count => 1 - assert_select "input", :count => 7 + assert_select "button[type=button]", :text => "Edit", :count => 1 + assert_select "button[type=button]", :text => "Preview", :count => 1 + assert_select "input", :count => 5 end end