Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only remove attachment upload button after trix has initialized #3464

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export default class extends Controller {
connect() {
if (this.attachmentsDisabledValue) {
// Remove the attachments button
this.controllerTarget.querySelector('.trix-button-group--file-tools').remove()
window.addEventListener('trix-initialize', (event) => {
if (event.target === this.editorTarget) {
this.controllerTarget.querySelector('.trix-button-group--file-tools').remove()
}
})
}

window.addEventListener('trix-file-accept', (event) => {
Expand Down
8 changes: 4 additions & 4 deletions lib/avo/fields/trix_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def is_action_text?
private

def disable_attachments?(args)
# If we don't have an attachment_key, we disable attachments. There's no point in having
# attachments if we can't store them.
return false if args[:attachment_key].present?
# Return the value of attachments_disabled if explicitly provided
return args[:attachments_disabled] unless args[:attachments_disabled].nil?

args[:attachments_disabled] == true
# Disable attachments if attachment_key is not present
args[:attachment_key].blank?
end
end
end
Expand Down
Loading