aboutsummaryrefslogtreecommitdiffstats
path: root/actiontext
diff options
context:
space:
mode:
authorAbhay Nikam <nikam.abhay1@gmail.com>2019-02-21 22:13:57 +0530
committerAbhay Nikam <nikam.abhay1@gmail.com>2019-02-22 10:18:21 +0530
commitb3778c5708f430da968e2a6995741fc082e92156 (patch)
tree659bb4d4d02d885decbf359c25e1bac10ae0f762 /actiontext
parent3b6602aa7a01fb415fce07ef32458b131e5762e1 (diff)
downloadrails-b3778c5708f430da968e2a6995741fc082e92156.tar.gz
rails-b3778c5708f430da968e2a6995741fc082e92156.tar.bz2
rails-b3778c5708f430da968e2a6995741fc082e92156.zip
Allows rich_text_area_tag to add I18n translated placeholder text if placeholder option set to true
Diffstat (limited to 'actiontext')
-rw-r--r--actiontext/app/helpers/action_text/tag_helper.rb4
-rw-r--r--actiontext/test/template/form_helper_test.rb50
2 files changed, 52 insertions, 2 deletions
diff --git a/actiontext/app/helpers/action_text/tag_helper.rb b/actiontext/app/helpers/action_text/tag_helper.rb
index 8434f2c611..1dc6202ae1 100644
--- a/actiontext/app/helpers/action_text/tag_helper.rb
+++ b/actiontext/app/helpers/action_text/tag_helper.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require "action_view/helpers/tags/placeholderable"
+
module ActionText
module TagHelper
cattr_accessor(:id, instance_accessor: false) { 0 }
@@ -35,6 +37,8 @@ end
module ActionView::Helpers
class Tags::ActionText < Tags::Base
+ include Tags::Placeholderable
+
delegate :dom_id, to: ActionView::RecordIdentifier
def render
diff --git a/actiontext/test/template/form_helper_test.rb b/actiontext/test/template/form_helper_test.rb
index a8c7a4dae2..cf7e4c0c69 100644
--- a/actiontext/test/template/form_helper_test.rb
+++ b/actiontext/test/template/form_helper_test.rb
@@ -5,6 +5,26 @@ require "test_helper"
class ActionText::FormHelperTest < ActionView::TestCase
tests ActionText::TagHelper
+ def form_with(*)
+ @output_buffer = super
+ end
+
+ teardown do
+ I18n.backend.reload!
+ end
+
+ setup do
+ I18n.backend.store_translations("placeholder",
+ activerecord: {
+ attributes: {
+ message: {
+ title: "Story title"
+ }
+ }
+ }
+ )
+ end
+
test "form with rich text area" do
form_with model: Message.new, scope: :message do |form|
form.rich_text_area :content
@@ -61,7 +81,33 @@ class ActionText::FormHelperTest < ActionView::TestCase
output_buffer
end
- def form_with(*)
- @output_buffer = super
+ test "form with rich text area having placeholder without locale" do
+ form_with model: Message.new, scope: :message do |form|
+ form.rich_text_area :content, placeholder: true
+ end
+
+ assert_dom_equal \
+ '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \
+ '<input type="hidden" name="message[content]" id="message_content_trix_input_message" />' \
+ '<trix-editor placeholder="Content" id="message_content" input="message_content_trix_input_message" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/:signed_id/:filename">' \
+ "</trix-editor>" \
+ "</form>",
+ output_buffer
+ end
+
+ test "form with rich text area having placeholder with locale" do
+ I18n.with_locale :placeholder do
+ form_with model: Message.new, scope: :message do |form|
+ form.rich_text_area :title, placeholder: true
+ end
+ end
+
+ assert_dom_equal \
+ '<form action="/messages" accept-charset="UTF-8" data-remote="true" method="post">' \
+ '<input type="hidden" name="message[title]" id="message_title_trix_input_message" />' \
+ '<trix-editor placeholder="Story title" id="message_title" input="message_title_trix_input_message" class="trix-content" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/:signed_id/:filename">' \
+ "</trix-editor>" \
+ "</form>",
+ output_buffer
end
end