Friday, April 15, 2011

Getting the Display value of a variable reference field

Getting the Display value of a variable reference field

On occasion there is need to get the display value of reference variable.
There are two ways to accomplish this first is make the call back to the server and query the table.

The second and more efficient way is to use get display box function of g_form.


var refFieldDispVal = g_form.getDisplayBox('the reference field').value;


Thanks to Mark Stanger for this pointer.

Adding a Reference Field to a UI Page

The following code is required to add a reference field to a UI Page. Note this does have type ahead on it as well.

This example references the sys_user table and only returns accounts which are active and not locked out.

To use this code add it to the html section of the ui_page.

<j:set var="jvar_user_query" value="QUERY:active=true^locked_out=false" />

<input id="user_query" type="hidden" value="${jvar_user_query}" />



<g:ui_reference name="${jvar_user_query}" table="sys_user" />



This enables the use of a reference field when custom forms are required.

JavaScript Code Snippet: Find and Replace all

Here is a JavaScript code snippet for a find and replace all.

This example code finds if there is an instance of three dashes in the string and replaces with three spaces.


if(str.indexOf('---') != -1){
str = str.replace(/---/g,' ');
}