diff --git a/app/javascript/js/controllers/fields/trix_field_controller.js b/app/javascript/js/controllers/fields/trix_field_controller.js index f61f016a96..d20e9a70fd 100644 --- a/app/javascript/js/controllers/fields/trix_field_controller.js +++ b/app/javascript/js/controllers/fields/trix_field_controller.js @@ -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) => { diff --git a/lib/avo/fields/trix_field.rb b/lib/avo/fields/trix_field.rb index fd16d473a8..020d238533 100644 --- a/lib/avo/fields/trix_field.rb +++ b/lib/avo/fields/trix_field.rb @@ -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