0

Suppose I have some model instances, (that I don't call from an angularJS file but from my rails controller)

 = f.fields_for :models, model do |builder|
          %ul
            = builder.hidden_field :some_id
            = check_box_tag :id => "some_value"

I want to add some_value as a value to the hidden_field as soon as the checkbox is checked. How can I do that with angularJS ?

1 Answer 1

1

First, if you're generating AngularJS HTML files as rails views you are somehow defying one of the purposes of AngularJS: being a client side templating system, based on static files.

(see these slides to get an idea: http://www.slideshare.net/JamieDavidson2/rails-angular-meetup)

regarding your question, you have to setup an Angular controller to define a scope, then link the value of the check_box_tag to the scope using ng-model and that of the hidden_field to the same model but through a function that gives the right string based on the checkbox state.

If you want to keep it simple, for this use case you'd better use JQuery

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

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.