Inside of my ActiveAdmin Rails6 app I've got below partial which replaces the standard input by editor.js (there is some JS magic behind, not relevant to this question). The partial and render look like below:
# _editor.html.erb
<%= f.input field, as: :hidden, input_html: { id: :editor_field } %>
<div style='width: 100%; background: white;' id="editorjs"></div>
# example of a parital call for field :body
<%= render 'admin/editor_js', f: f, field: :body %>
Because ActiveAdmin is based on formatic gem instead of this partial I want to create and use custom input based on :text field. I was trying to do something like below.
module CustomInputs
class EditorJsInput < Formtastic::Inputs::TextInput
def input_html_options
super.merge(input_html: { id: 'editor_field' }).merge(as: :hidden)
end
end
end
(as: :hidden) is not working and no idea how to add this empty div at the end <div style='width: 100%; background: white;' id="editorjs"></div> which is quite crucial.
as: :hiddenis not an input_html_option, it's an input style/type that maps the input to the Inputs::HiddenInput type; all it really does is render the input field as a hidden list item. Additionally, the way you're overridinginput_html_optionsis not correct:Please review the docu and source on the methods you are trying to override:
An overridden
input_html_optionsmethod would be something like this if you're looking to override the existing ID:Presuming that you're really looking to reliably know the ID so some JS can find the element and swap it out, you could either specify it in the
input_htmlhash when declaring your form input or, more cleanly, simply use the autogenerated ID. Generally the ID is the the underscore-separated form object root key + the attribute name; so if your form object iscoffee: { name: 'Goblin Sludge', origin_country: 'Columbia' }, I believe the default is forf.input :nameto render withid='coffee_name'andf.input :origin_countryto render withid='coffee_origin_country'. This is stuff that you can easily figure out by using the devtools inspector on the rendered form.It seems like you really are looking to override to_html. You need something like this:
This should build the input for
f.object.nameas something like<input id="coffee_name" type="hidden" value="Goblin Sludge" name="coffee[name]">(see FormBuilder#hidden_fieldAdditional thoughts: