Thursday, April 24, 2014

Creating bespoke ajax lookups in BlueBox

BlueBox includes a default ajax-lookup feature for lists of information. This provides a neat facility for any link-table lookups and works by simply naming your fields with a capital ID in the field name ie userISbb_usersID.

Sometimes you want to use your own ajax lookups and there is a quick bbsetting that allows you to override the standard lookup, called bbsetting_ajax_lookup_jsfunction.

If you enter your javascript replacement function name into this setting for the required module, it will use that function rather than the standard one, ie my_lookup_function

A hidden div is automatically created with an id 'div_{field_name}' whenever a field for that module is created, so you can hook your ajax lookup into that div and the text input field is automatically given the id 'viewer_{field_name}' - with these 2 id's you have the ingredients to build an ajax lookup.

Your javascript lookup would work this way:

function my_lookup_function(){
  \$('div_global[fields][userISbb_usersID]').style.display='block';
  ajax2div('div_global[fields][userISbb_usersID]','/?class=my_class&method=my_method&global[noincludes]=rawtext&global[srch_txt]='+$('viewer_global[fields][userISbb_usersID]').value);
}

In your my_class->my_method you would then search the module using $global[srch_txt] and return the results.

No comments:

Post a Comment