diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-02-01 23:42:38 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-02-01 23:42:38 +0000 |
commit | fdcf4d6c5191b25ee3b6c357dafaf17156eb09d3 (patch) | |
tree | 347f771202054a443f9df23a8f65f91d49a52209 /actionpack/lib/action_view/helpers/form_helper.rb | |
parent | 27fa38cc3e162b2f8c4bb2d50130fbc17bad6039 (diff) | |
parent | 16c0d1d3b6089bb4b0b0baf7c3eeb5949f31f02b (diff) | |
download | rails-fdcf4d6c5191b25ee3b6c357dafaf17156eb09d3.tar.gz rails-fdcf4d6c5191b25ee3b6c357dafaf17156eb09d3.tar.bz2 rails-fdcf4d6c5191b25ee3b6c357dafaf17156eb09d3.zip |
Merge remote branch 'mainstream/master'
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 157deebe40..1d91b6957a 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -225,6 +225,33 @@ module ActionView # ... # <% end %> # + # === Unobtrusive JavaScript + # + # Specifying: + # + # :remote => true + # + # in the options hash creates a form that will allow the unobtrusive JavaScript drivers to modify its + # behaviour. The expected default behaviour is an XMLHttpRequest in the background instead of the regular + # POST arrangement, but ultimately the behaviour is the choice of the JavaScript driver implementor. + # Even though it's using JavaScript to serialize the form elements, the form submission will work just like + # a regular submission as viewed by the receiving side (all elements available in <tt>params</tt>). + # + # Example: + # + # <% form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f| %> + # ... + # <% end %> + # + # The HTML generated for this would be: + # + # <form action='http://www.example.com' id='create-post' method='post' data-remote='true'> + # <div style='margin:0;padding:0;display:inline'> + # <input name='_method' type='hidden' value='put' /> + # </div> + # ... + # </form> + # # === Customized form builders # # You can also build forms using a customized FormBuilder class. Subclass @@ -280,9 +307,11 @@ module ActionView args.unshift object end + options[:html][:remote] = true if options.delete(:remote) + concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {})) fields_for(object_name, *(args << options), &proc) - concat('</form>'.html_safe!) + safe_concat('</form>') end def apply_form_for_options!(object_or_array, options) #:nodoc: @@ -850,7 +879,7 @@ module ActionView end hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => options['disabled'] && checked ? checked_value : unchecked_value) checkbox = tag("input", options) - (hidden + checkbox).html_safe! + (hidden + checkbox).html_safe end def to_boolean_select_tag(options = {}) |