I'm looking for some guidance to make a custom form with ActiveAdmin. This is not a regular form, but I actually need some JavaScript on it. However, I'm not familiar with ActiveAdmin right now.
I have a form that will collect a Product list. Every time I add a Product to the list, I need to recalculate the sub-total for the order (based on quantity and unique price).
For adding the products I'm using regular Formtastic, like this:
f.inputs "Product List" do
f.has_many :product_lists do |detail|
detail.input :good_id, :as => :select,
:collection => Good.accessible_by(current_ability, :read),
:input_html => { class: 'chosen-select' },
:include_blank => true
detail.input :quantity, :input_html => { :value => 1 }
end
end
However, I came across to multiple questions:
If you are using >= 1.0.0.pre from the master branch:
has_many
block inside of an f.inputs
block if you want them to be in a panel. Is your total being recalculated on the server side or on the client side when you add items? If on the server side, the total should be updated after the form is submitted, and that logic probably belongs in your model. AA has-many adds fields to the form, which in turn gets submitted and then committed. Adding a new nested fieldset does not change anything on the server until the whole form is submitted. If it should be updated without committing, you'll need to handle the ajax request and responses yourself, but you should be able to simply use the default actions and either request the json format back or create a custom javascript template.