Page 1 of 1

Datepicker linked field

Posted: Mon Jan 15, 2018 6:05 am
by mpol_ch

Hi,
I am using the following to fields with Datepicker button:

Kaufdatum
Instdatum

When I enter the date with calendar button into field "Kaufdatum" then I want to insert in same time date+3 Year into field "Instdatum".

Exp:
Kaufdatum: 27.01.2018
Instdatum: 27.01.2021

Where should I start?

mpol_ch


Re: Datepicker linked field

Posted: Mon Jan 15, 2018 3:49 pm
by arbei

in [Edit Tag] -> [Client side events] add the code to the change event.

  1. When the value changed, get the value of the field and use .toJsDate() to get the Date object.
  2. Use the date object and add the number of date to it.
  3. Assign the calculated value to the 2nd field.

Read the example and the field plugin in help file topic: "Server Events and Client Scripts" -> "Startup Script" for more information.


Re: Datepicker linked field

Posted: Mon Jan 15, 2018 5:59 pm
by mpol_ch

Hi,

the below code is not working for me. The field "Instdatum" is being changed once I edited the field manually.
I want to have the date entry with calendar button for field "Kaufdatum" and to have the same date entered into field "Instdatum".
The best would be: Instdatum = Kaufdatum + 3Years

{ // keys = event types, values = handler functions
"change": function(e) {
var $row = $(this).fields();
var kdatum= $row["Kaufdatum"].toJsDate();
$row["Instdatum"].value(kdatum).toJsDate();
}
}

Any hints?

mpol_ch


Re: Datepicker linked field

Posted: Tue Jan 16, 2018 12:53 pm
by arbei

Tested your code and found that using the "focusout" event is better to monitor the change from the datetimepicker.

And your code is missing the "DateAdd" part.

Search the "Javascript DateAdd" in Google and there are some useful links for your reference.

For example:
var kdatum= $row["Kaufdatum"].toJsDate();
kdatum.setDate(kdatum.getDate() + 360);
//Code to format the date as your expected format and put it back to field "Instdatum".


Re: Datepicker linked field

Posted: Wed Jan 17, 2018 4:47 am
by mpol_ch

Hi arbei,

it does not work for me.
The target field is being changed when I edit the source field manually.
I want to enter the target date entered when I entered or edited the source field with calendar button.

I checked the internet with search terms "bootstrap datepicker linked fields" but can not find something the I can use.

mpol_ch


Re: Datepicker linked field

Posted: Wed Jan 17, 2018 10:20 am
by arbei

Have you changed the event listener to "focusout"?


Re: Datepicker linked field

Posted: Wed Jan 17, 2018 7:22 pm
by mpol_ch

Hi arbei,

no. You mean change the "change" to "focusout" in edit view for client script?

mpol_ch


Re: Datepicker linked field

Posted: Thu Jan 18, 2018 11:25 am
by arbei

You need to change it to "focusout". Because select the date from datetimepicker will not trigger the change event of the field.