Skip to content

Commit

Permalink
Apply field_error_proc to rich_text_area fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiquekandykoga authored and jonathanhefner committed Dec 22, 2022
1 parent de40fc6 commit 0dc71ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actiontext/CHANGELOG.md
@@ -1,3 +1,7 @@
* Apply `field_error_proc` to `rich_text_area` form fields.

*Kaíque Kandy Koga*

* Action Text attachment URLs rendered in a background job (a la Turbo
Streams) now use `Rails.application.default_url_options` and
`Rails.application.config.force_ssl` instead of `http://example.org`.
Expand Down
3 changes: 2 additions & 1 deletion actiontext/app/helpers/action_text/tag_helper.rb
Expand Up @@ -50,7 +50,8 @@ def render
options = @options.stringify_keys
add_default_name_and_id(options)
options["input"] ||= dom_id(object, [options["id"], :trix_input].compact.join("_")) if object
@template_object.rich_text_area_tag(options.delete("name"), options.fetch("value") { value }, options.except("value"))
html_tag = @template_object.rich_text_area_tag(options.delete("name"), options.fetch("value") { value }, options.except("value"))
error_wrapping(html_tag)
end
end

Expand Down
19 changes: 19 additions & 0 deletions actiontext/test/template/form_helper_test.rb
Expand Up @@ -69,6 +69,25 @@ def form_with(*, **)
output_buffer
end

test "form with rich text area and error wrapper" do
message = Message.new
message.errors.add(:content, :blank)

form_with model: message, scope: :message do |form|
form.rich_text_area :content
end

assert_dom_equal \
'<form action="/messages" accept-charset="UTF-8" method="post">' \
'<div class="field_with_errors">' \
'<input type="hidden" name="message[content]" id="message_content_trix_input_message" autocomplete="off" />' \
'<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">' \
"</trix-editor>" \
"</div>" \
"</form>",
output_buffer
end

test "form with rich text area for non-attribute" do
form_with model: Message.new, scope: :message do |form|
form.rich_text_area :not_an_attribute
Expand Down

0 comments on commit 0dc71ac

Please sign in to comment.