require File.dirname(__FILE__) + '/tag_helper' module ActionView module Helpers # Provides a set of helpers for calling JavaScript functions and, most importantly, to call remote methods using what has # been labelled AJAX[http://www.adaptivepath.com/publications/essays/archives/000385.php]. This means that you can call # actions in your controllers without reloading the page, but still update certain parts of it using injections into the # DOM. The common use case is having a form that adds a new element to a list without reloading the page. # # To be able to use the JavaScript helpers, you must either call <%= define_javascript_functions %> (which returns all # the JavaScript support functions in a ' end # Observes the field with the DOM ID specified by +field_id+ and makes # an AJAX call when its contents have changed. # # Required +options+ are: # :url:: +url_for+-style options for the action to call # when the field has changed. # # Additional options are: # :frequency:: The frequency (in seconds) at which changes to # this field will be detected. Not setting this # option at all or to a value equal to or less than # zero will use event based observation instead of # time based observation. # :update:: Specifies the DOM ID of the element whose # innerHTML should be updated with the # XMLHttpRequest response text. # :with:: A JavaScript expression specifying the # parameters for the XMLHttpRequest. This defaults # to 'value', which in the evaluated context # refers to the new field value. # # Additionally, you may specify any of the options documented in # +link_to_remote. def observe_field(field_id, options = {}) if options[:frequency] and options[:frequency] > 0 build_observer('Form.Element.Observer', field_id, options) else build_observer('Form.Element.EventObserver', field_id, options) end end # Like +observe_field+, but operates on an entire form identified by the # DOM ID +form_id+. +options+ are the same as +observe_field+, except # the default value of the :with option evaluates to the # serialized (request string) value of the form. def observe_form(form_id, options = {}) if options[:frequency] build_observer('Form.Observer', form_id, options) else build_observer('Form.EventObserver', form_id, options) end end # Adds AJAX autocomplete functionality to the text input field with the # DOM ID specified by +field_id+. # # This function expects that the called action returns a HTML