Skip to content

Commit 0dc71ac

Browse files
kaiquekandykogajonathanhefner
authored andcommitted
Apply field_error_proc to rich_text_area fields
1 parent de40fc6 commit 0dc71ac

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

actiontext/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Apply `field_error_proc` to `rich_text_area` form fields.
2+
3+
*Kaíque Kandy Koga*
4+
15
* Action Text attachment URLs rendered in a background job (a la Turbo
26
Streams) now use `Rails.application.default_url_options` and
37
`Rails.application.config.force_ssl` instead of `http://example.org`.

actiontext/app/helpers/action_text/tag_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def render
5050
options = @options.stringify_keys
5151
add_default_name_and_id(options)
5252
options["input"] ||= dom_id(object, [options["id"], :trix_input].compact.join("_")) if object
53-
@template_object.rich_text_area_tag(options.delete("name"), options.fetch("value") { value }, options.except("value"))
53+
html_tag = @template_object.rich_text_area_tag(options.delete("name"), options.fetch("value") { value }, options.except("value"))
54+
error_wrapping(html_tag)
5455
end
5556
end
5657

actiontext/test/template/form_helper_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ def form_with(*, **)
6969
output_buffer
7070
end
7171

72+
test "form with rich text area and error wrapper" do
73+
message = Message.new
74+
message.errors.add(:content, :blank)
75+
76+
form_with model: message, scope: :message do |form|
77+
form.rich_text_area :content
78+
end
79+
80+
assert_dom_equal \
81+
'<form action="/messages" accept-charset="UTF-8" method="post">' \
82+
'<div class="field_with_errors">' \
83+
'<input type="hidden" name="message[content]" id="message_content_trix_input_message" autocomplete="off" />' \
84+
'<trix-editor 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/redirect/:signed_id/:filename">' \
85+
"</trix-editor>" \
86+
"</div>" \
87+
"</form>",
88+
output_buffer
89+
end
90+
7291
test "form with rich text area for non-attribute" do
7392
form_with model: Message.new, scope: :message do |form|
7493
form.rich_text_area :not_an_attribute

0 commit comments

Comments
 (0)