Skip to content

Instantly share code, notes, and snippets.

@donnfelker
Last active September 16, 2025 11:39
Show Gist options
  • Save donnfelker/9e74a93371084955d557d219e5adea7a to your computer and use it in GitHub Desktop.
Save donnfelker/9e74a93371084955d557d219e5adea7a to your computer and use it in GitHub Desktop.
Images only and Disable Uploads for Lexxy Editor
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
// Disable Lexxy uploads by preventing all file-accept events
document.addEventListener("lexxy:file-accept", function(event) {
console.log("file uploads not allowed")
event.preventDefault();
});
}
}
<%# This will give you the ability to provide UI feedback (via the stimulus controller) to the user of why %>
<%= form.rich_text_area :body, data: { controller: "disable-uploads" } %>
<%# This is the default mechanism to block attachments, but with no UI feedback of why %>
<%= form.rich_text_area :body, attachments: false %>
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
document.addEventListener("lexxy:file-accept", function(event) {
// Only allow jpg/jpeg, png and gif images
const acceptedTypes = ['image/jpeg', 'image/png', 'image/gif']
if (!acceptedTypes.includes(event.detail.file.type)) {
event.preventDefault()
alert("We only support jpeg, png or gif files")
}
})
}
}
<%= form.rich_text_area :body, data: { controller: "images-only" } %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment