--- !ruby/object:RI::MethodDescription 
aliases: []

block_params: 
comment: 
- !ruby/struct:SM::Flow::P 
  body: Observes the field with the DOM ID specified by <tt>field_id</tt> and calls a callback when its contents have changed. The default callback is an Ajax call. By default the value of the observed field is sent as a parameter with the Ajax call.
- !ruby/struct:SM::Flow::P 
  body: "Example:"
- !ruby/struct:SM::Flow::VERB 
  body: " # Generates: new Form.Element.Observer('suggest', 0.25, function(element, value) {new Ajax.Updater('suggest',\n #         '/testing/find_suggestion', {asynchronous:true, evalScripts:true, parameters:'q=' + value})})\n &lt;%= observe_field :suggest, :url =&gt; { :action =&gt; :find_suggestion },\n      :frequency =&gt; 0.25,\n      :update =&gt; :suggest,\n      :with =&gt; 'q'\n      %&gt;\n"
- !ruby/struct:SM::Flow::P 
  body: "Required <tt>options</tt> are either of:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "<tt>:url</tt>:"
    body: <tt>url_for</tt>-style options for the action to call when the field has changed.
  - !ruby/struct:SM::Flow::LI 
    label: "<tt>:function</tt>:"
    body: "Instead of making a remote call to a URL, you can specify javascript code to be called instead. Note that the value of this option is used as the <b>body</b> of the javascript function, a function definition with parameters named element and value will be generated for you for example:"
  - !ruby/struct:SM::Flow::VERB 
    body: "  observe_field(&quot;glass&quot;, :frequency =&gt; 1, :function =&gt; &quot;alert('Element changed')&quot;)\n"
  - !ruby/struct:SM::Flow::P 
    body: "will generate:"
  - !ruby/struct:SM::Flow::VERB 
    body: "  new Form.Element.Observer('glass', 1, function(element, value) {alert('Element changed')})\n"
  - !ruby/struct:SM::Flow::P 
    body: The element parameter is the DOM element being observed, and the value is its value at the time the observer is triggered.
  type: :NOTE
- !ruby/struct:SM::Flow::P 
  body: "Additional options are:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "<tt>:frequency</tt>:"
    body: 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.
  - !ruby/struct:SM::Flow::LI 
    label: "<tt>:update</tt>:"
    body: Specifies the DOM ID of the element whose innerHTML should be updated with the XMLHttpRequest response text.
  - !ruby/struct:SM::Flow::LI 
    label: "<tt>:with</tt>:"
    body: A JavaScript expression specifying the parameters for the XMLHttpRequest. The default is to send the key and value of the observed field. Any custom expressions should return a valid URL query string. The value of the field is stored in the JavaScript variable <tt>value</tt>.
  - !ruby/struct:SM::Flow::P 
    body: Examples
  - !ruby/struct:SM::Flow::VERB 
    body: "  :with =&gt; &quot;'my_custom_key=' + value&quot;\n  :with =&gt; &quot;'person[name]=' + prompt('New name')&quot;\n  :with =&gt; &quot;Form.Element.serialize('other-field')&quot;\n"
  - !ruby/struct:SM::Flow::P 
    body: Finally
  - !ruby/struct:SM::Flow::VERB 
    body: "  :with =&gt; 'name'\n"
  - !ruby/struct:SM::Flow::P 
    body: is shorthand for
  - !ruby/struct:SM::Flow::VERB 
    body: "  :with =&gt; &quot;'name=' + value&quot;\n"
  - !ruby/struct:SM::Flow::P 
    body: This essentially just changes the key of the parameter.
  - !ruby/struct:SM::Flow::LI 
    label: "<tt>:on</tt>:"
    body: Specifies which event handler to observe. By default, it's set to &quot;changed&quot; for text fields and areas and &quot;click&quot; for radio buttons and checkboxes. With this, you can specify it instead to be &quot;blur&quot; or &quot;focus&quot; or any other event.
  type: :NOTE
- !ruby/struct:SM::Flow::P 
  body: Additionally, you may specify any of the options documented in the <em>Common options</em> section at the top of this document.
- !ruby/struct:SM::Flow::P 
  body: "Example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  # Sends params: {:title =&gt; 'Title of the book'} when the book_title input\n  # field is changed.\n  observe_field 'book_title',\n    :url =&gt; 'http://example.com/books/edit/1',\n    :with =&gt; 'title'\n\n  # Sends params: {:book_title =&gt; 'Title of the book'} when the focus leaves\n  # the input field.\n  observe_field 'book_title',\n    :url =&gt; 'http://example.com/books/edit/1',\n    :on =&gt; 'blur'\n"
full_name: ActionView::Helpers::PrototypeHelper#observe_field
is_singleton: false
name: observe_field
params: (field_id, options = {})
visibility: public
