bookmark_bordergform_format_option_label

Description

This filter is executed when calculating and displaying the pricing on product option fields (also for product and shipping fields set as drop down field type). 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 integer

    The current form ID.

  • fieldId integer

    The current field ID.

Examples

Example 1

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>

Example 2

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>

Example 3

This example replaces the variable pricing with the static full option price

<script type="text/javascript">

function gform_format_option_label(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId) {
    if ( fieldId != 43 ) {
        return fullLabel;
    }
    priceLabel = " <span class='ginput_price'>" + gformFormatMoney(price) + '</span>';
    return fieldLabel + priceLabel;
}

</script>

Placement

This code should be placed in an HTML field on your form or you may use the gform_pre_render hook to echo the script block to the page.

Source Code

This filter is located in gravityforms.js