Hi all, I'm working on legacy project with rails 2.3.5, ruby 1.8.7 and 
active_scaffold 2.3 

So my problem is following - i need to implement following behavior
1. user see list of records in the table
2. user press 'copy' button
3. new record create form appear, similar to usual create form but all 
fields inside form are populated as in orginal record (note that there are 
associations for record, and values for selection for one association 
depend on selection on another - for usual create behavior this is solved 
with :update_columns )
4. user review form, change something and press 'save' after that record is 
persisted into db

Trying to implement such behavior I finally ended up with rjs scripting. 
But I have some problem in that area which I'd like to describe below and 
maybe someone here could provide better solution for it. 

My solution was following:
1. in controller action which is called by member link 'copy' I've add 
observe js function which will be called on click of 'create' link 

document.getElementById('as_payments-new--link').observe('click', 
fillsenderaccount())


2. inside function fillsenderaccount() i did population of all parameters. 

But  problem I encountered that 'create form' is loaded in async mode via 
ajax and also that on load it doesn't change really any element on page, 
instead it just create new element with its own id. so I was not able to 
figure out which javascript callback and on which object can I use to make 
my function fillsenderaccount() after and only after completion of form 
rendering and loading. 

For making it work I ended up with adding timeout of ~500msec for execution 
of my function, to make it work only after form has appeared:
function fillsenderaccount(){
  setTimeout(
    function fillsender(){
     ...
    }
  ,500)//added time delay to let 'create form' load on screen
}

document.getElementById('as_payments-new--link').observe('click', 
fillsenderaccount())

I know that timeout solution is ugly and unreliable speaking in short, and 
moreover, because I have linked sets of attributes on form, it was required 
to copycat same faulty approach for population of dependent attributes. I 
mean it wait 500ms to let form load, then it wait another 300-700ms in 
other functions to let selected values appear and dependent values to 
refresh, only after that dependent associations were loaded and set 
successfully.

My question after all is if anyone struggled with same problem and if so, 
have you managed to find what callback and for which dom element to use to 
make user-defined callbacks to work after and only after successful load of 
create form (or other form for ex update) without using timeouts, but some 
queues or something else. I'm not specialist in javascript so if you could 
recommend, please let me know.

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails Gem" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/activescaffold.
For more options, visit https://groups.google.com/d/optout.

Reply via email to