Datepicker linked field

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mpol_ch
User
Posts: 877
Location: Switzerland

Datepicker linked field

Post 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


arbei
User
Posts: 9281

Post 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.


mpol_ch
User
Posts: 877
Location: Switzerland

Post 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


arbei
User
Posts: 9281

Post 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".


mpol_ch
User
Posts: 877
Location: Switzerland

Post 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


arbei
User
Posts: 9281

Post by arbei »

Have you changed the event listener to "focusout"?


mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

Hi arbei,

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

mpol_ch


arbei
User
Posts: 9281

Post by arbei »

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


Post Reply