gooweb
(gooweb)
January 18, 2024, 1:13pm
1
Hi,
I’m using Gravity Forms in order to display a calculator / simulator.
The form contains two or three Number fields to field.
At the bottom, I have one Number field with calculation enabled.
Here is a screenshot : Screenshot by Lightshot
I would like to hide the thousands separator (a comma).
I found something in the documentation here : gform_include_thousands_sep_pre_format_number - Gravity Forms
I created the following snippet :
add_filter(
'gform_include_thousands_sep_pre_format_number'
,
'__return_false'
);
But it seems not working.
Any idea please ?
richardw8k
(Richard Wawrzyniak (Gravity Forms))
January 18, 2024, 1:55pm
2
The gform_include_thousands_sep_pre_format_number filter doesn’t apply to the live form, it only applies when the entry value is formatted for display on the list and detail pages, or when merge tags output the values in confirmations and notifications.
To change the formatting of a calculation result on the front-end, you’ll need to use the JavaScript-based gform_calculation_format_result filter:
1 Like
gooweb
(gooweb)
January 18, 2024, 3:08pm
3
Thank you for your answer.
I tried this, but it doesn’t work …
<script>
gform.addFilter('gform_calculation_format_result', function(formattedResult, result, formulaField, formId, calcObj) {
// Retirer le séparateur de milliers (virgule ou point)
formattedResult = formattedResult.replace(/[,\.]/g, '');
return formattedResult;
});
</script>
gooweb
(gooweb)
January 31, 2024, 3:07pm
4
Hi,
I’m not a developer and I still need help on this.
Please could you help me again ?
Hi there,
Could you please let me know how or where you’ve tried the provided JavaScript code which wasn’t working? Is it possible to share the live form URL so I can further investigate to resolve it?
gooweb
(gooweb)
February 2, 2024, 8:33am
6
Hi,
Here is the live form URL : Approvisionnement restaurant optimisé via contrôle d'accès
I used the WPCode Lite plugin to insert the code.
Thanks.
First, get the field ID from the edit form page, like the screenshot below.
Then, try the following code.
gform.addFilter('gform_calculation_format_result', function (formattedResult, result, formulaField, formId, calcObj) {
if (formulaField.field_id == '4') { // field ID
formattedResult = result.toFixed(0);
}
return formattedResult;
});
The output will look like the following screen recording.
Give it a try, and let me know how that goes!
It appears that your field ID is the same as mine, so it’s 4 and you can use my provided code without modification. Here is the preview:
gooweb
(gooweb)
February 5, 2024, 2:08pm
9
Faisal Ahammad:
gform.addFilter('gform_calculation_format_result', function (formattedResult, result, formulaField, formId, calcObj) {
if (formulaField.field_id == '4') { // field ID
formattedResult = result.toFixed(0);
}
return formattedResult;
});
It works, thank you very much !
1 Like
system
(system)
Closed
February 14, 2024, 4:37am
10
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.