]> git.openstreetmap.org Git - rails.git/commitdiff
Switch to edit pane if rich text field validation fails
authorAnton Khorev <tony29@yandex.ru>
Wed, 14 Aug 2024 13:43:57 +0000 (16:43 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 14 Aug 2024 13:43:57 +0000 (16:43 +0300)
Allows the "Please fill out this field" message to be visible.

app/assets/javascripts/richtext.js
test/system/rich_text_test.rb [new file with mode: 0644]

index 1576656eece0a21f91457a548a5c2b4279dc52f7..e069f6f88007cbfc4d732cac5ac08116b18bab49 100644 (file)
@@ -8,6 +8,10 @@ $(document).ready(function () {
     var container = $(this).closest(".richtext_container");
 
     container.find(".tab-pane[id$='_preview']").empty();
+  }).on("invalid", function () {
+    var container = $(this).closest(".richtext_container");
+
+    container.find("button[data-bs-target$='_edit']").tab("show");
   });
 
   /*
diff --git a/test/system/rich_text_test.rb b/test/system/rich_text_test.rb
new file mode 100644 (file)
index 0000000..6876718
--- /dev/null
@@ -0,0 +1,16 @@
+require "application_system_test_case"
+
+class RichTextSystemTest < ApplicationSystemTestCase
+  def setup
+    create(:language, :code => "en")
+  end
+
+  test "switches to edit pane on validation failure" do
+    sign_in_as create(:user)
+    visit new_diary_entry_path
+    fill_in "Subject", :with => "My Diary Entry Title"
+    click_on "Preview"
+    click_on "Publish"
+    assert_field "Body"
+  end
+end