Gform format option label

Description

This filter is executed when calculating and displaying the pricing on option fields. Use this filter to change the format of the option field labels. Can be used to disable or change the format of the price displayed on option fields.

Usage

<script type="text/javascript">

//Simply implement the function with name "gform_format_option_label" to activate the javascript filter. The value returned by this function will be used as the option label.

function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId){ 

      //disabling option pricing. simply return the field label.
      return fieldLabel; 
}

</script>

Parameters

fullLabel
(string) The default label that will be displayed for the current option. It has the field choice label as well as the calculated price. (i.e. My Option +$5.00)
fieldLabel
(string) The field/option label without the price. (i.e. My Option)
priceLabel
(string) The price text without the field label. (i.e. +$5.00)
selectedPrice
(float) The price of the currently selected option.
price
(float) The price of this option. (The option that this label applies to)
formId
(int) The current form ID.
fieldId
(int) The current field ID.

Examples

The following example disables the option pricing, displaying only the option label.

<script type="text/javascript">
           
function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId){ 

      //disabling option pricing. simply return the field label.
      return fieldLabel; 
}
        </script>


The following example changes the order of the labels, displaying the option price before the field label. I only does that for form ID 5.

<script type="text/javascript">
           
function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId){ 

      //ignore all forms, except the one with ID = 5
      if(formId != 5)
          return fullLabel;

      //ignore all fields except the one with ID = 10
      if(fieldId != 10)
         return fullLabel;

      //changing label
      return priceLabel + " " + fieldLabel; 
}
        </script>

Source Code

This filter is located in gravityforms.js

Search the Documentation