Make jsoneditor in Active Admin read-only through Ruby?

882 Views Asked by At

I'm editing a form in Active Admin/Formtastic, which includes a jsoneditor input. Under some circumstances, though, the JSON should be locked and uneditable, in which case I'd want to use the view mode so it can be read but not changed. Is there a way to do this on the Ruby side? The current code looks something like this.

form do |f|
    f.inputs do
        input(:my_data, as: :jsonb)
    end
end

I've tried as: :text, input_html: { disabled: true }, but that makes the JSON pretty much unreadable.

1

There are 1 best solutions below

0
On

You could wrap you JSON in a <code> block using ActiveAdmin's Arbre for cases when it should be readonly. Here's a rough example:

Arbre::Context.new do
  code JSON.pretty_generate(:my_data)
end