javascript - How do you get a JS DOM/JQuery Object for Form Tag in form_remote_tag's :complete callback? -


in rails 2.3.3, want like:

<% form_remote_tag :url => "/some/path/", :loading => "loadingfunction(this)", :complete => "completefunction(this,request)" %> 

basically, want able pass specific form tag :complete or :loading callback functions (in relative way - don't want use id - want able tag :complete call corresponds natural result of :complete call being form tag**).

see rails documentation form_remote_tag. in particular, rails generates code following onsubmit event: new ajax.request('/some/path/', {asynchronous:true, evalscripts:true, oncomplete:function(request){completefunction(this,request)}, onloading:function(request){loadingfunction(this)}, parameters:form.serialize(this)}); return false;" . note how function calls wrapped within function(request){} inside new ajax.request().

so, "this", "jquery(this)", "jquery(this).closest('.someparentelementoftheform')" etc. don't work.


**i doing because: i'm rendering arbitrary number of "form_remote_tag"s when page loaded, , user can trigger events cause arbitrarily more "form_remote_tag"s appear (with similar content in each form, amount of elements in each form arbitrary). if have 1 form_remote_tag in entire page, there few main problems:

  • the user editing 1 section of page (which in current design corresponds 1 form), of form elements' data in page have sent in request

  • it require sort of messy way keep track of forms , elements, giving them ids such as: 'form-12','form-12-paramfield-13' etc.

  • it makes difficult allow: user submit 1 form, , while form loading via ajax, submit other forms (including possibility of triggering event causes new form appear , submitting form), because of issues keeping track of put response data each request

have tried passing below callbacks in html options like

:html => { :loading => "#{remotefunction(options)}; return false;" } or :html => { :onloading => "#{remotefunction(options)}; return false;" }

the callbacks may specified (in order):

:loading:   called when remote document being loaded data browser. :loaded:    called when browser has finished loading remote document. :interactive:   called when user can interact remote document, though has not finished loading. :success:   called when xmlhttprequest completed, , http status code in 2xx range. :failure:   called when xmlhttprequest completed, , http status code not in 2xx range. :complete:  called when xmlhttprequest complete (fires after success/failure if present). 

you can further refine :success , :failure adding additional callbacks specific status codes.

recently have achieved overiride onsubmit in 1 remote forms below

 <% options = {:url => {:action =>"test", :id => 1}, :with =>"form.serialize('test_form')" }%>  <% form_remote_tag :html=>{ :onsubmit =>"#{remote_function(options)}; return false" } %> 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -