Font Size:
Ask Joget AI

FormUtil

This page details the FormUtil endpoints and the actions they support. It covers key functions, parameters, and sample code for easy implementation.

  • URL: /jw/js/json/formUtil.js
  • Auto included in page using form.
  • Convenient method to interact with form field.

 

getField(fieldId, element)

Used to gets the field object of a form field.

  • Parameters:
    • fieldId - id of a form field
    • element - optional element to search within; defaults to the document body
  • Sample code:
var field = FormUtil.getField("field1");
$(field).val("test"); //set value

 

getFieldsAsUrlQueryString(fields, element)

Used to generate the field value as url query parameter string.

  • Parameters:
    • fields - an array contains objects with "field", "param" and "defaultValue" attributes.
      • field: id of a form field
      • param: parameter name to be used
      • defaultValue: value to be used when the field return empty value (Optional)
    • element - optional element to search within; defaults to the document body
  • Sample code:
var fields = [
    {"field":"field1", "param":"p_field1"},
    {"field":"field2", "param":"p_field2"},
    {"field":"field3", "param":"p_field3", "defaultValue":"default value"},
];
  
var queryString = FormUtil.getFieldsAsUrlQueryString(fields);
console.log(queryString); //p_field1=Field1%20value&p_field2=Field2%20value;Field2%20second%20value&p_field3=default%20value

 

getGridCells(cellFieldId, element)

Used to get the cell objects of every row of a grid field.

  • Parameters:
    • cellFieldId - Grid Field Id and the cell id separated by a dot ".". Eg. gridId.cellId
    • element - optional element to search within; defaults to the document body
  • Sample code: 
var cells = FormUtil.getGridCells("gridId.field1");
$(cells).each(function(){
    //do something
});

 

getGridCellValues(cellFieldId, element)

Used to get the cell values of every row of a grid field and return it in an array.

  • Parameters:
    • cellFieldId - Grid Field Id and the cell id separated by a dot ".". Eg. gridId.cellId
    • element - optional element to search within; defaults to the document body
  • Sample code:
var values = FormUtil.getGridCellValues("gridId.field1");
for (var i = 0; i < values.length; i++) {
    console.log(values[i]); //i equals to row number start from 0
}

 

getValue(fieldId, element)

Used to get the value of a form field.

  • Parameters:
    • fieldId - id of a form field
    • element - optional element to search within; defaults to the document body
  • Sample code.
var value = FormUtil.getValue("field1");

 

// you could also use it to get value from a subform
// FormUtil.getValue("subformElementId_subformTargetFormId_subformFieldID")
 
// using Expenses Claim App as an example, and you are in the ExpensesClaim form and wish to get the title value from the subform
// parent form ID = ExpensesClaim
// subform ID in parent form = sfD
// child form ID = ExpensesClaimNew
// the field ID = title
 
var value = FormUtil.getValue("sfD_ExpensesClaimNew_title")
 

getValues(fieldId, element)

Used to get the values of a form field. Values will return in an array. 

  • Parameters:
    • fieldId - id of a form field
    • element - optional element to search within; defaults to the document body
  • Sample code: 
var values = FormUtil.getValues("field1");
for (var i = 0; i < values.length; i++) {
    console.log(values[i]);
}

 

 

setControlField(fieldId, selector)

Marks a field as a control field so it can be identified by isControlField.

  • Parameters:
    • fieldId - id or name of the field to mark
    • selector - optional selector for the field element to mark; when omitted, elements with the matching field name are used
  • Sample code:
FormUtil.setControlField("field1");

 

isControlField(fieldId, field)

Checks whether a field has been marked as a control field.

  • Parameters:
    • fieldId - id or name of the field to check
    • field - optional field element to check for the control-field class
  • Returns: true if the field is registered or has the control-field class; otherwise false
  • Sample code:
var field = FormUtil.getField("field1");
var isControl = FormUtil.isControlField("field1", field);

 

numberFormat(value, options)

Formats a numeric value using the provided number-format options.

  • Parameters:
    • value - numeric value as a string
    • options - format settings:
      • numOfDecimal - number of decimal places
      • format - use "EURO" for comma decimals and dot grouping; other values use dot decimals and comma grouping
      • useThousandSeparator - string "true" to enable grouping, or "false" to disable it
      • prefix and postfix - text added before or after the formatted number
  • Sample code:
var formatted = FormUtil.numberFormat("1234.5", {
    numOfDecimal: 2,
    format: "US",
    useThousandSeparator: "true",
    prefix: "$",
    postfix: ""
});
console.log(formatted); // $ 1,234.50

 

populateTooltip(tooltips)

Adds tooltip icons to matching form-field labels using the supplied tooltip text.

  • Parameters:
    • tooltips - object mapping keys prefixed with tooltip_ and field IDs to tooltip text
  • Sample code:
FormUtil.populateTooltip({
    "tooltip_field1": "Help text for this field"
});
Created by Aadrian Last modified by Debanraj Ravindran on Nov 13, 2026