Archive for April, 2014

simple_form with AngularJS

Maybe I’ll stop monkeying with code, but here’s a time saver.  Couldn’t find a great solution to add ng-model’s to my bootstrap forms to bind AngularJS and certainly this doesn’t take the cake, but it does add my model names for my ng-models with simple_form.  Comment if you find issues in your code.  (Note: You will want to change the wrapper name here to ~namespace it to your wrapper). I did this to avoid conflicts on non-angular forms.

 module SimpleForm
   module Inputs
     class Base
       def input_html_options
         if @builder.options[:wrapper] == :bootstrap_angular
@input_html_options.reverse_merge!({ "ng-model" => "#{@builder.lookup_model_names.join(".")}.#{self.attribute_name}" })
       end
       @input_html_options
     end
   end
 end
 
© 2012 - Jeff Ancel
Wordpress Themes
Scroll to Top