Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By shuqierduo
#790024
I have a Dynaform with two dates, "EffectiveFrom" and "EffectiveTo"

When user opens a form the "EffectiveFrom" should be set to the current date + 1 day. I can use trigger to pre-populate the date but how can I implement control so that user can only choose a later date not earlier?

Another rule is that the "EffectiveTo" date should always be 1 year after the "EffectiveFrom" date or later. I tried the StrToTime() function but it is not available on the form javascript. Is there an alternative way to do so?
#790031
To set the minimum allowed date, see:
http://wiki.processmaker.com/3.1/Dateti ... _variables

Set @@minDateFrom in the "min date" property of your "EffectiveFrom" datetime field. Also set the @@minDateTo in the "min date" property of your "EffectiveTo" datetime field.

Then add the following trigger to your process, which is set to fire before the DynaForm:
Code: Select all
$tomorrow = strtotime('+1 day');
$nextYear = strtotime('+1 year', $tomorrow);
@@EffectiveFrom = date('Y-m-d', $tomorrow);
@@minDateFrom = @@EffectiveFrom;
@@EffectiveTo = date('Y-m-d', $nextYear);
@@minDateTo = @@EffectiveTo;
This trigger will set the minimum dates that the user can select.

Then add the following JavaScript to your DynaForm:
Code: Select all
//change event handler to set the Effective To date to one year later
//when the Effective From date changes
$("#EffectiveFrom").setOnchange(function(newVal, oldVal) {
  if (newVal != '') {
    var startDate = moment(newVal);
    var endDate = moment(startDate).add(1, 'Y').format("YYYY-MM-DD");
    $("#EffectiveTo").setValue(endDate);
  }
});

//change event handler to verify that the EffectiveTo date is at least a year 
//after the EffectiveFrom date
$("#EffectiveTo").setOnchange(function(newVal, oldVal) {
  if (newVal != '') {
    var fromDate = $("#EffectiveFrom").getValue();
    var endDate = moment(fromDate).add(1, 'Y').format("YYYY-MM-DD");
    if (moment(newVal).format("YYYY-MM-DD") < endDate) {
      alert("The Effective To date must be at least a year after the Effective From date.");
      $("#EffectiveTo").setValue(endDate);
    }
  }
});
Here is a sample process which shows how this code works:
(40.22 KiB) Downloaded 176 times

As you have got seen that after every single updat[…]

issue with processmaker 3.2

Hello! The solution to your question is the foll[…]

BPMN project disappeared

Hi Alex! , maybe you forgot to save your process[…]

mcrypt extension is deprecated!

Hello Ehsan! If you did not find the mcrypt ext[…]