Page 1 of 1

Update Date Field automatically

Posted: 28 May 2018
by TWendt
Hi all,
is it possible to update the Kendo Date Time field automatically. I mean, i have a start date and time. When i switch to the due date field, the field should update from the start date field.

Best wishes
Tom :?:

Re: Update Date Field automatically

Posted: 28 May 2018
by Nikita Kurguzov
Dear Tom,
Yes, of course! Please, check out the following article - https://spform.com/javascript-framework ... eld-values
It shows you how to detect change in any of the fields, how to get the current value and how to set a new value to a field. All you need to do, is write the code to detect change in a field Start Date and to update the Due Date properly.

For example:

Code: Select all

fd.field('StartDate').change(function(){
  var startDate = fd.field('StartDate').control('getDate');
  var dueDate = new Date();
  var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
  dueDate.setTime(startDate.getTime() + weekInMilliseconds);
  fd.field('DueDate').value(dueDate);
});

Re: Update Date Field automatically

Posted: 28 May 2018
by TWendt
Hi Nikita,

do you have an example for me?

Best wishes
Tom

Re: Update Date Field automatically

Posted: 28 May 2018
by Nikita Kurguzov
Dear Tom,
Yes, I was just testing it out for you, it's in my first reply now. Check it out, but don't forget to replace StartDate and DueDate with correct InternalNames of the fields, I do not know them, but you can check them in the designer, when you select a field. Also, I am adding a week, but you can add any amount of days instead.

Re: Update Date Field automatically

Posted: 16 Oct 2018
by TWendt
Sorry for the late delay,
the script doesn't work.
Here is my script

fd.field('Anfangsdatum').change(function(){
var startDate = fd.field('Anfangsdatum').control('getDate');
var dueDate = new Date();
var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
dueDate.setTime(startDate.getTime() + weekInMilliseconds);
fd.field('Fälligkeitsdatum').value(dueDate);
});

Best wishes
Tom

Re: Update Date Field automatically

Posted: 17 Oct 2018
by AlexZver
Hi Tom,

The example was for the DateTime field with a default template.
A code for the field with a Kendo template (your choice, as I understand) will be slightly different:

Code: Select all

fd.field('Anfangsdatum').change(function(){
    var startDate = fd.field('Anfangsdatum').value();
    var dueDate = new Date(); 
    var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
    dueDate.setTime(startDate.getTime() + weekInMilliseconds);
    fd.field('Fälligkeitsdatum').value(dueDate);
});

Re: Update Date Field automatically

Posted: 01 Nov 2018
by Cassidy
Hi Alex, so this specific code will only work with a Kendo template and no other?

Re: Update Date Field automatically

Posted: 01 Nov 2018
by Nikita Kurguzov
Dear Cassidy,
Use the following code for default Date field:

Code: Select all

fd.field('StartDate').change(function(){
  var startDate = fd.field('StartDate').control('getDate');
  var dueDate = new Date();
  var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
  dueDate.setTime(startDate.getTime() + weekInMilliseconds);
  fd.field('DueDate').value(dueDate);
});
And the following code for Kendo Date field:

Code: Select all

fd.field('StartDate').change(function(){
    var startDate = fd.field('StartDate').value();
    var dueDate = new Date(); 
    var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
    dueDate.setTime(startDate.getTime() + weekInMilliseconds);
    fd.field('DueDate').value(dueDate);
});
I hope this will help you, as these are the only two options for date fields available in Forms Designer by default. If you have any questions - let us know!