Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Subform lookup and Javascript - how pass row information

Post Reply
agnar
Posts: 37
Joined: Sun Apr 21, 2013 10:58 pm

Subform lookup and Javascript - how pass row information

Unread post 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...)
agnar
Posts: 37
Joined: Sun Apr 21, 2013 10:58 pm

Re: Subform lookup and Javascript - how pass row information

Unread post 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 = '';
            }
        } 
    }

}
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

Re: Subform lookup and Javascript - how pass row information

Unread post by admin »

agnar,

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

But this might be what you were looking for..

nuGetRow();

http://wiki.nubuilder.com/tiki-index.ph ... #nuGetRow_

Steven
Post Reply