Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/avo/fields/trix_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def attachments_disabled
# Disable attachments if attachment_key is not present
@attachment_key.blank?
end

def component_for_view(view)
if view.edit? && (is_readonly? || is_disabled?)
Avo::Fields::TrixField::ShowComponent
else
super
end
end
end
end
end
38 changes: 38 additions & 0 deletions spec/system/avo/trix_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,44 @@
end
end
end

describe "trix field with disabled/readonly set to true" do
let!(:body) { "This is test content for disabled state" }
let!(:post) { create :post, body: body }

context "when disabled is set to true" do
it "displays show page content when disabled is set to true for a trix field" do
Avo::Resources::Post.with_temporary_items do
field :body, as: :trix, disabled: true
end

visit "/admin/resources/posts/#{post.id}/edit"

expect(page).not_to have_selector("trix-editor")

expect(page).to have_selector(".trix-content")
expect(page).to have_text(body)

Avo::Resources::Post.restore_items_from_backup
end
end
context "when readonly is set to true" do
it "displays show page content when readonly is set to true for a trix field" do
Avo::Resources::Post.with_temporary_items do
field :body, as: :trix, readonly: true
end

visit "/admin/resources/posts/#{post.id}/edit"

expect(page).not_to have_selector("trix-editor")

expect(page).to have_selector(".trix-content")
expect(page).to have_text(body)

Avo::Resources::Post.restore_items_from_backup
end
end
end
end

def fill_in_trix_editor(id, with:)
Expand Down
Loading