3

How to add javascript action with formastic and activeadmin:

I have such form:

f.input :role, :as => :select, :collection => User.display_roles.each_with_index.map{|x,i|  [x,User.roles[i]]} , :include_blank => nil

f.input :organization, :input_html => { :disabled => false }

I would like to add javascript in which after change a role, organization will change. How to do it??

2 Answers 2

2

I had to create a form partial.

At the end of the partial put:

<script type="text/javascript">     
    $(function(){
        $('#your_model_role').change(function() {
            what you want to happen goes here
        });
    });
</script>

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

2

Following the idea of not having obtrusive js you can also put this into a js file (example: utils.js):

$(function(){
    $('#your_model_role').change(function() {
        what you want to happen goes here
    });
});

And then in /config/initializers/active_admin.rb put a line config.register_javascript 'utils.js'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.