Hi,

I'm a recent convert to jQuery, and so far, so great! I'm slowly  
moving through my home rolled javascript and migrating it across. One  
script which I'm desperate to fix is a generic 'addSubform' routine  
which I use to create a new child form (say address form) for a parent  
form (say organisation). I use a hidden template, which the routine  
clones and then renumbers (The back end is php so I need child forms  
inputs to be renumbered so that they end up as PHP arrays; the  
template fields are all prefixed with 'tmpl_' so I strip that and  
rename the input like so:

theName = theName.replace("tmpl_","");
node.name = prefix+'[' + subformCount + '][' + theName + ']' ;

The original function is roughly this:

function addSubform(childtype) {
   subformCount++;
   var mysubform = document.getElementById(childtype 
+'_tmpl').cloneNode(true);
   mysubform.id = '';
   mysubform.style.display = 'block';
   // traverse all of the childnodes of mysubform
   depthTraverse (mysubform, renumberFormField, childtype );
   var insertHere = document.getElementById(childtype+'_insert');
   insertHere.parentNode.insertBefore(mysubform,insertHere);
   return false;
}

As I'm sure you've spotted - the depthTravers is the killer. It works,  
but is a pain for subforms with large 'select' popups.

I can see that being able to use a .filter() on inputs and textareas  
should make this much quicker ;-) but I'm still at the larval noobie  
stage and can't quite see how to do the renaming. I suspect I'm trying  
to do too much in one line!

Also - the inputs within the field will have their events attached -  
it seems to suggest that I can copy attached events over as well,  
using .clone(true) - is this actually the case, and what should I  
watch for?

I'm sure that this is the sort of thing that jQuery maestros run off  
all the time. Hoping someone point me in the right direction...

Kind regards,

R


--
Richard Dyce MA (Cantab.) MBCS MIET

Reply via email to