Skip to content

Conversation

zhephyn
Copy link
Contributor

@zhephyn zhephyn commented Jun 12, 2025

Description

The Trix field has no straightforward way to render disabled input. To bypass this, the suggested approach was to render the Trix show component within the edit form if either disabled or readonly is set to true.

Show page
image

Edit page
image

The body of the event is shown instead of the Trix field editor on the Edit page when disabled or readonly are set to true like below:

field :body, as: :trix, disabled: true

Fixes #3888

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Copy link

qlty-cloud-legacy bot commented Jun 12, 2025

Code Climate has analyzed commit 4911fb7 and detected 0 issues on this pull request.

View more on Code Climate.

@zhephyn
Copy link
Contributor Author

zhephyn commented Jun 12, 2025

@Paul-Bob I've laid out an initial approach to fix the Trix field readonly bug

However currently the edit_component.html.erb file could use some refactoring, specifically the show component duplication. I was thinking of extracting the show component into a partial but wanted to run it by you first and see if you think its a sustainable approach.

Lmk what you think. Thanks

@zhephyn
Copy link
Contributor Author

zhephyn commented Jun 12, 2025

I've added tests for this as well.

Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zhephyn, you're on fire! Thanks for this contribution.

The approach is on the right track, but I think we can achieve a more elegant execution.

Take a look at how the component_for_view method works, every field has it, and it essentially returns the component used to render a field based on the current view.

We can override that method within the Trix field file and perform the readonly/disabled check there. If the view is a form (view.form?) and the field is readonly or disabled, the method can return the show component instead. This way, we avoid burdening the edit component with duplicative logic from the show component.

Let me know if this makes sense or if you have any questions.

Thanks again, really appreciate your contributions!

@zhephyn
Copy link
Contributor Author

zhephyn commented Jun 13, 2025

@Paul-Bob New changes are up. Kindly take a look whenever its convenient for you.

@zhephyn zhephyn requested a review from Paul-Bob June 14, 2025 21:18
Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thank you @zhephyn

@Paul-Bob Paul-Bob merged commit a501b76 into avo-hq:main Jun 17, 2025
20 checks passed
@zhephyn zhephyn deleted the fix-disabled-and-readonly-for-trix-field branch June 19, 2025 08:40
@Paul-Bob Paul-Bob added the Fix label Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix disabled and readonly on trix
2 participants