Reload Calculated Field

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Mapleleaf
Posts: 29
Joined: Tue Oct 25, 2016

10 Jan 2019

Hello!
I have a form with field x and field y. Third field is a calculated sharepoint-field z which is (x+y).

Is it possible to refresh value of z after x or y has changed?

User avatar
AlexZver
Posts: 232
Joined: Mon Aug 27, 2018

10 Jan 2019

Hi!

This is only possible with JavaScript. You need to subscribe to change events on these fields and run a calculation function when the value changes. More on this for various fields here - https://spform.com/javascript-framework ... eld-values

You can change the value of the calculated field by using jQuery:

1) Add a CSS class to the field in Forms Designer, e.g. "calc_field"
Screenshot_128.png
Screenshot_128.png (2.96 KiB) Viewed 2547 times
2) Add a code:

Code: Select all

$(".calc_field").find(".ms-formbody").html(newValue);
Where "newValue" is a recalculated value.

If you have any questions - let me know!

Mapleleaf
Posts: 29
Joined: Tue Oct 25, 2016

11 Jan 2019

Works! :D

Thank you

crolle
Posts: 7
Joined: Sun Oct 22, 2017

27 Mar 2019

Where should I write the code

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

28 Mar 2019

Dear crolle,
This code is executed from JS editor:
JS editor.png
JS editor.png (8.6 KiB) Viewed 2492 times
For example, you want to combine Title and Status field. It should look something like this:

Code: Select all

function updateCalcField(){
  var newValue = fd.field('Title').value() + " " + fd.field('Status').value();
  $(".calc_field").find(".ms-formbody").html(newValue);
}

fd.field('Title').change(function(){
  updateCalcField();
});

fd.field('Status').change(function(){
  updateCalcField();
});
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests