Question

I need to trigger some javascript to load up an extra part of a form in activeadmin. For the "create" action I've successfully triggered the javascript from the onchange event of a dropdown box, but for the edit action it needs to be triggered from the form load.

I've found I can trigger it with something similar to

javascript_tag "loadRecipeEdit(3)"

but I can't embed this into the form action for activeadmin without it breaking the structure of the form (formtastic issue)

form do |f|
    f.inputs "Details" do
        f.input :name
        f.input :production_date
        if f.object.new_record?
            f.input :recipe, :input_html => { :onchange => "loadRecipe()" } 
        else
           javascript_tag "loadRecipeEdit(3)" 
        end
    end
    f.actions
end

Any thoughts of other ways to trigger the javascript would be much appreciated!

Was it helpful?

Solution

Ah, found an alternative:

f.form_buffers.last << javascript_tag("loadRecipeEdit(3)")

Hope its useful!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top