Page 1 of 1

Subform lookup and Javascript - how pass row information

PostPosted: Sat May 11, 2013 5:36 am
by agnar
When passing "this" as a parameter on the on blur or on change call, it'll pass the object where the event occurred.

In my case, upon selecting an item from a lookup object in a subform, say a book, I need to compose a string for a description field to contain multiple fields from that record, for example "<book title>, <author>, (<isbn>)".

Shouldn't be too difficult to call a function from the Javascript item of the lookup and do that. But when I pass "this" to this function, I receive an undefined object.

How do I obtain the row number of a lookup object in a the lookup javascript action.

(I generally find the nubuilder documentation rather terse...)

Re: Subform lookup and Javascript - how pass row information

PostPosted: Thu May 23, 2013 6:02 am
by agnar
Found a solution:

Add a field to the subform that is not associated with any database field, call it xxx_clicked, for example.

Use the 'Update other fields' subform of the lookup object to assign any database field, the primary key is a good choice, to the xxx_clicked field.

Then call subform_lookup_clicked() in the Javascript entry of the lookup object.

Then the following custom code will do the trick:
Code: Select all
function subform_lookup_clicked()
    formName = 'my_subform';
    rowCount = Number(document.getElementById('rows' + formName).value);

    for (rowIndex = 0;rowIndex < rowCount; ++rowIndex)

        indexStr   = '0000'+rowIndex;
        indexStrLen      = indexStr.length;
   rowPrefix        = formName + indexStr.substring(indexStrLen-4);

   if (document.getElementById( "row"+rowPrefix).checked != true)
            // the lookup will assign the primary key of the selected item to the xxx_clicked field
            // this is the way we detect which row was clicked.
            was_clicked = document.getElementById( rowPrefix + 'xxx_clicked').value != '';
            if (was_clicked)
                 // then do something with this row
                // reset the xxx_clicked field
                document.getElementById( rowPrefix + 'xxx_clicked').value = '';


Re: Subform lookup and Javascript - how pass row information

PostPosted: Fri Aug 23, 2013 10:42 am
by admin

We will be doing our best to improve documentation in nuBuilder version 3.

But this might be what you were looking for..