You could use an array/object to hold all of your fields:

var field_array = [];

for(var i=1; i<=total_field_sets; i++){
        ...
        var field = new ftmDataEntryTextfield(...);
        if(i<=25){
                ...
                field.setLeft(left_col_booking_ref_x);
                splitpane.addLeft(..., field,...);
        } else {
                ...
                field.setLeft(right_col_booking_ref_x);
                splitpane.addRight(..., field,...);
        }
        var field_name = "booking_ref_" + i;
        field_array[field_name] = field;
}

...

for(var i=1; i<=total_field_sets; i++){
        // reconstruct the field name:
        var field_name = "booking_ref" + i; 
        // look up the field from the array:
        var field = field_array[field_name];

        // access data in the field:
        field.setValue( ... );
}

and so on.  You get the idea.  This can then be extended to sets of
arrays for labels, fields, attributes, etc.

Thanks,

Steven

On Wed, 2008-01-16 at 14:44 -0800, Aaron Cooper wrote:
> Hi there, I've been playing with this for a day, and the form actually
> displays correctly, but I am unable to access each new field at a later
> stage for populating with data in another loop.
> 
> What I have is a form where the user can insert up to 50 passenger names.
> Rather than define and add each field individually, I created the following
> loop:
> 
> // Iterate through a loop to add many field sets
>   var current_y_pos = 25;
>   for(var i=1; i<=total_field_sets; i++) {
>     // If we are up to item field set 26, we are shifting columns, so set
> the y pos to the top again
>     if(i == 26) {
>       current_y_pos = 25;
>     }
>     
>     var number_lbl_var = 'lbl_number_' + i;
>     var fname_var = 'pax_fname_' + i;
>     var sname_var = 'pax_sname_' + i;
>     var booking_ref_var = 'booking_ref_' + i; 
>     
>     var number_lbl_var = new
> ftmDataEntryFieldLabel(number_lbl_var,current_y_pos,i);
>     var fname_var = new ftmDataEntryTextfield(fname_var,current_y_pos,125);
>     var sname_var = new ftmDataEntryTextfield(sname_var,current_y_pos,125);
>     var booking_ref_var = new
> ftmDataEntryTextfield(booking_ref_var,current_y_pos,100);
>     
>     if(i<=25) {
>     left_col_number_x
>       number_lbl_var.setLeft(left_col_number_x);
>       fname_var.setLeft(left_col_fname_x);
>       sname_var.setLeft(left_col_sname_x);
>       booking_ref_var.setLeft(left_col_booking_ref_x);
>      
> splitpane.addLeft(eval(fname_var),eval(sname_var),eval(booking_ref_var),eval(number_lbl_var));
>     } else {
>       number_lbl_var.setLeft(right_col_number_x);      
>       fname_var.setLeft(right_col_fname_x);
>       sname_var.setLeft(right_col_sname_x);
>       booking_ref_var.setLeft(right_col_booking_ref_x);
>      
> splitpane.addRight(eval(fname_var),eval(sname_var),eval(booking_ref_var),eval(number_lbl_var));
>     }
>     
>     current_y_pos = current_y_pos + 25;
>   }
> 
> This works fine. However I have this block further down the page for
> populating the form when it loads:
> 
>   var editDataAjax = new sack();
>   editDataAjax.reset();
>   editDataAjax.requestFile = "ajax/get_all_passengers.php";
>   editDataAjax.method = 'post';
>   editDataAjax.encVar("booking_id", edit_booking_id);
>   editDataAjax.onCompletion = whenGetChargeDataComplete;
>   editDataAjax.runAJAX();
>   
>   function whenGetChargeDataComplete() {
>     passenger_string = editDataAjax.response;
>     passenger_array = passenger_string.split('*EOR*');
>     
>     for(var i=0; i<passenger_array.length; i++) {
>       if(passenger_array[i] != '') {
>         var passenger = passenger_array[i].split('*EOF*');
>         eval('pax_fname_' + (i+1)).setValue(passenger[1]);
>       }
>     }
>   }
>   // End of obtaining data
> 
> The data is also being obtained correctly too.
> 
> I can see that the problem lies in the second block where the fields are
> defined:
> 
>     var number_lbl_var = new
> ftmDataEntryFieldLabel(number_lbl_var,current_y_pos,i);
>     var fname_var = new ftmDataEntryTextfield(fname_var,current_y_pos,125);
>     var sname_var = new ftmDataEntryTextfield(sname_var,current_y_pos,125);
>     var booking_ref_var = new
> ftmDataEntryTextfield(booking_ref_var,current_y_pos,100);
> 
> Obviously all the fields are named the same despite me setting them up
> before hand. I have tried 
> 
>    var eval(number_lbl_var) = new
> ftmDataEntryFieldLabel(number_lbl_var,current_y_pos,i);
> 
> But this only throws and error.
> 
> Can anyone advise on how I should be doing this? I don't want to hard code
> each field, as there are 4 per passenger, and the client's requirement may
> change the number of passengers required.
> 
> Cheers
> Aaron
> 
> 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Dynamic-Form-Elements-created-in-a-For-loop-tp14896459p14896459.html
> Sent from the qooxdoo-devel mailing list archive at Nabble.com.
> 
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to