☰
Documentation

Developer Filters

Advanced Number Field has two PHP filters and one JavaScript filter for developers. Use them to hide thousands separators, to switch HTML5 number inputs to text inputs, or to change the text next to a slider. Add the PHP filters to the functions.php file of your (child) theme or to a code snippets plugin.

gravitywp_anf_show_thousands_sep

Controls whether the thousands separator is shown when Advanced Number Field formats the value of a field in the form, in the browser: in the input after typing, in calculation results and in the slider output. It applies to the Number formats 9,999.99 and 9.999,99, and to crore notation with these formats; the Currency format keeps the separators of the currency.

apply_filters( 'gravitywp_anf_show_thousands_sep', bool $show, GF_Field $field )
ParameterDescription
$showtrue (default) to show the thousands separator, false to hide it.
$fieldThe Number or Quantity field.

Example: hide the thousands separator for field 3 of form 1, so 1,234.56 is shown as 1234.56.

add_filter( 'gravitywp_anf_show_thousands_sep', function ( $show, $field ) {
if ( (int) $field->formId === 1 && (int) $field->id === 3 ) {
return false;
}
return $show;
}, 10, 2 );

This filter only changes the formatting in the form. For the formatted value in the entries, merge tags, GravityView and Gravity PDF, Advanced Number Field uses the Gravity Forms filter gform_include_thousands_sep_pre_format_number, with the same parameters.

gravitywp_anf_decimal_dot_number_input

Number fields with the Number format 9,999.99 and no Advanced Number Field settings keep the HTML5 number input (type="number"), as in Gravity Forms. Fields with an Advanced Number Field setting, or with another Number format, always get a text input. Return true from this filter to switch the plain 9,999.99 fields to a text input too. Fields with Show as Slider are not affected.

apply_filters( 'gravitywp_anf_decimal_dot_number_input', bool $convert, GF_Field $field, string $value, int $entry_id, int $form_id )
ParameterDescription
$convertfalse (default) keeps the number input, true changes it to a text input.
$fieldThe Number or Quantity field.
$valueThe field value.
$entry_idThe entry ID, when an entry is being edited.
$form_idThe form ID.

Example: use text inputs for all number fields of form 5.

add_filter( 'gravitywp_anf_decimal_dot_number_input', function ( $convert, $field, $value, $entry_id, $form_id ) {
if ( (int) $form_id === 5 ) {
return true;
}
return $convert;
}, 10, 5 );

gravityWP.advancedNumberField.sliderOutput

A JavaScript filter that changes the text that is shown next to a slider. It is purely visual: it does not change the value of the field.

gform.addFilter( 'gravityWP.advancedNumberField.sliderOutput', function ( value, rawValue, formFieldID, properties ) {
return value;
} );
ArgumentDescription
valueThe formatted value, including the custom unit when one is set.
rawValueThe numeric value of the slider, as a string with a decimal dot.
formFieldIDThe form ID and field ID, like 1_23.
propertiesThe Advanced Number Field settings of the field.

Return the text to show. See Range Slider Settings for an example that shows “100 or more”.

gravitywp_anf_show_thousands_sep gravitywp_anf_decimal_dot_number_input gravityWP.advancedNumberField.sliderOutput
Proudly powered by WordPress