Setting Start and End Dates

Questions and discussion about using ProcessMaker 2: user interface, running cases and functionality

Moderator: amosbatto

Forum rules
Please search to see if a question has already been asked before posting. Please don't ask the same question in multiple forums.
ic57369k
Posts: 7
Joined: Fri Sep 01, 2017 2:14 am
Country: India

Setting Start and End Dates

Unread postby ic57369k » Sun Sep 24, 2017 7:49 am

Hello,
I have a dynaform where I am choosing start and end dates from the calender. I want to impose following validation rules
1. Start date should be atleast today. Cant be before current date.
2. End date cant be earlier than start date.
3. End Date cant be more than 60 days ahead than start date.
Need a suitable java script.
Thanks and regards

amosbatto
Posts: 5566
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: Setting Start and End Dates

Unread postby amosbatto » Tue Sep 26, 2017 1:03 am

I don't have time right now to work on this, but you should see this post to get started and look at the documentation for moment.js.
viewtopic.php?f=41&t=713762&p=795579#p795579
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

amosbatto
Posts: 5566
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: Setting Start and End Dates

Unread postby amosbatto » Tue Sep 26, 2017 11:04 pm

I had some time to play with this.
First, create a DynaForm which has two datetime fields whose IDs and variables are named "startDate" and "endDate". In each of these field, set their "min date" properties to be: @@minDate
Set these two datetime fields to be required.

Second, add the following JavaScript to the DynaForm:

Code: Select all

getFormById( $("form").prop("id") ).setOnSubmit( function() {
  var startDate = moment( $("#startDate").getValue() );
  var endDate   = moment( $("#endDate").getValue() );
  var diff = endDate.diff(startDate, 'days');
 
  if (diff < 0) {
    alert("The End Date must be after the Start Date.");
    return false;
  }
  else if (diff > 60) {
    alert("The End Date must not be more than 60 days after the Start Date.");
    return false;
  }
});


Third, create a trigger in the process with the following code:

Code: Select all

@@minDate date('Y-m-d'); 

Set this trigger to fire before the DynaForm.

Here is a sample process to test it:
Set_date_limits-2.pmx
(36.49 KiB) Downloaded 3 times
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

amosbatto
Posts: 5566
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: Setting Start and End Dates

Unread postby amosbatto » Tue Sep 26, 2017 11:05 pm

I had some time to play with this.
First, create a DynaForm which has two datetime fields whose IDs and variables are named "startDate" and "endDate". In each of these field, set their "min date" properties to be: @@minDate
Set these two datetime fields to be required.

Second, add the following JavaScript to the DynaForm:

Code: Select all

getFormById( $("form").prop("id") ).setOnSubmit( function() {
  var startDate = moment( $("#startDate").getValue() );
  var endDate   = moment( $("#endDate").getValue() );
  var diff = endDate.diff(startDate, 'days');
 
  if (diff < 0) {
    alert("The End Date must be after the Start Date.");
    return false;
  }
  else if (diff > 60) {
    alert("The End Date must not be more than 60 days after the Start Date.");
    return false;
  }
});


Third, create a trigger in the process with the following code:

Code: Select all

@@minDate date('Y-m-d'); 

Set this trigger to fire before the DynaForm.

Here is a sample process to test it:
Set_date_limits-2.pmx
(36.49 KiB) Downloaded 4 times
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

ic57369k
Posts: 7
Joined: Fri Sep 01, 2017 2:14 am
Country: India

Re: Setting Start and End Dates

Unread postby ic57369k » Fri Sep 29, 2017 7:30 am

Extremely grateful. thanks and regards for the commitment and help.


Return to “Using ProcessMaker 2”

Who is online

Users browsing this forum: No registered users and 6 guests