How to format currency fields on the form

i have a issue in list and library control where first when i add item it woks and then i go and delete one of the item and try to add new item again it adds the row with undefined and disables the delete button if i click edit and change the value it work is it expected behaviour? i just want the row to be added as someone will add for the first time

image

@ShantiBhattarai,

Do you have any JavaScript in the form besides calculating the totals? Do you have any custom CSS?

Could you please share them so I could reproduce the issue on my side.

Hi Nikitina,

i dont have any other css or javascript beside calculating totals. i tried in new list with just the code for this.

@ShantiBhattarai,

Please share the complete code you are using in the form.

Is editing of List or Library control set to inline or dialog?
If it is a dialog, do you have any script in the child form?

Also, please check the app version in the console (F12). The latest version is 1.0.7. If the latest version not installed, please follow the instructions on how to Update the app package.

image

Hi Nikitina,

The version is latest and code is below. i don't have any other css or JS beside this. It just happens random if you delete the row and add again it will say undefined in the title field and also calculation of total works sometime and most of the time it recognizes the change only on delete event not when added when new item added it doesn't update total but if i delete one row it will update.

fd.spRendered(function() {

fd.control('SPDataTable1').$on('change', function() { 	
    fd.control('SPDataTable1').widget.bind("dataBound",function(){
        var data = fd.control('SPDataTable1').widget._data;			
        var TotalCost = 0;
        if(data){
            for (var i = 0; i < data.length; i++){
                                  TotalCost += parseInt(data[i].Cost.replace(/[^0-9.]/g, ""))*parseInt(data[i]. Cost1.replace(/[^0-9.]/g, ""));
			}
        }
        var amt =parseInt(TotalCost).toFixed(2);            
        fd.field('TotalCost').value = amt;
    })
});

})

@ShantiBhattarai,

Please try the code from the example from the post below and let me know if the problem persists. This code is more suitable for calculating totals if editing of List or Library control is inline, as it does calculation periodically, not on change.

it doesnt do anything no error but doesnt calculate total also one thing i noticed is if i create a new form and just close and try to create new one it is loading previous form which was not saved or which gave error while saving its caching somewhere item is not in list but if i open new form i can see old data which was not saved that might be an issue? gives error Cannot read property 'widget' of undefined while saving

@ShantiBhattarai,

This error might be caused by the incorrect name of the control in this line:

var value = fd.control('SPDataTable0').widget.dataItems();

Please check the internal name of List or Library control in the code.

Do you mean that the child items created for the previous unsaved entry are displayed in the new entry?

If the parent item with child elements has not been saved, child elements will be displayed to the user who created them in the new form. That is the expected behavior of the control.

yes for the second part it is true if it is expected behaviour and just shows to the one who created then it will be fine. But for the issue to calculate total the problem is still there it doesn't update the total cost field and i have defined right widget

var value = fd.control('SPDataTable1').widget.dataItems();

image

@ShantiBhattarai,

Is it possible to provide us temporary access to your tenant to troubleshoot the issue?

Please send us an email to support@plumsail.com

I wont be able do that i will try to create in new list again and see how it behaves

1 Like

Good news, everyone!
With the recent update to v1.6.1, we've added customization options for both Number and Currency field and now their format can be set in the editor - https://plumsail.com/docs/forms-sp/designer/fields-sp.html#designer-currency

The value retrieved with JS will stay the same number type, only presentation changes:
image

The Format option doesn't seem to apply itself if the Field is set to Read-only (which would be a normal thing to do if it is being calculated).

Notice that the Total Payment includes neither the currency symbol nor both digits of the last one is zero.

Hello @ShareSquared,

When you set a field to read-only, it is displayed based on column settings.

If you need to display a currency sign and a specific number of decimal places, you need to change the column settings.

As shown in the screenshot below, the column is already configured as a Currency column (has been since it was created).

And here are the properties of the Field control in the form:

Any ideas?

Hello @ShareSquared,

Please try to re-add the field to the form and clear the browser cache.

If that doesn't help, please make sure that you are using the latest versions of the app package in the App Catalog - v1.0.8.0 and the editor - v1.7.2

:heavy_check_mark: Cleared browser cache w/ Ctrl+F5


No Rounding? :point_down:

And the js:

Hiya @ShareSquared, sorry to but in, but if you are doing the calculation, then you need to format the answer how you want it to be displayed.

fd.field('TotalPayment').value = '$' + totalCost.toFixed(2)

So do the trick!

Hope I helped :slight_smile:

1 Like

Hello @ShareSquared,

Thank you for the details!

In a display form or read-only mode, the 'value' is just a text representation of the field. So when you change a field value, it is treated as a string, and no formatting is applied.

As a workaround, you can enable and hide TotalPayment field on the form, add Plain Text control to display total value formatted and add this code to calculate and display the total.

fd.control('liDataTable').$on('change', function(){
    items = fd.control('DataTable1').widget.dataItems();
    totalCost = 0.00;
       if(items) {
          for(i=0; i<items.length; i++) {
              if(items[i].liAmount){
                 totalCost += items[i].liAmount;
              }
          }
    fd.field('TotalPayment').value = totalCost;
    fd.control('Text1').text = 'Total: $' + totalCost;
}