Subform lookup and Javascript - how pass row information

Subform lookup and Javascript - how pass row information

Postby agnar » Sat May 11, 2013 5:36 am

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: Mon Apr 22, 2013 6:28 am

Re: Subform lookup and Javascript - how pass row information

Postby agnar » Thu May 23, 2013 6:02 am

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

}
agnar
 
Posts: 37
Joined: Mon Apr 22, 2013 6:28 am

Re: Subform lookup and Javascript - how pass row information

Postby admin » Fri Aug 23, 2013 10:42 am

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.php?page=Nubuilder%20Javascript%20Functions%3A%20Javascript%20Functions&structure=nuBuilderDocs#nuGetRow_

Steven
admin
Site Admin
 
Posts: 3154
Joined: Mon Jun 15, 2009 9:53 am


Return to Custom Code



cron