Clearing a datetime field

Unofficial documentation how to do interesting things and work around problems in ProcessMaker

Moderator: amosbatto

Forum rules
Unofficial documentation for features which have not been tested by Quality Assurance or may change in future versions of ProcessMaker
amosbatto
Posts: 5321
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Clearing a datetime field

Unread postby amosbatto » Fri Jan 27, 2017 8:08 pm

The setValue() method currently does not work to clear a datetime field.

Until this bug gets fixed, the way to clear a datetime field in ProcessMaker 3 is to use this JavaScript code:

Code: Select all

$("[id='form[datetimeID]']").val('');
$("[id='form[datetimeID_label]']").val('');
getFieldById("datetimeID").model.attributes.data.label='';
getFieldById("datetimeID").model.attributes.data.value='';


For example, a DynaForm has a datetime field with the ID of "dueDate". A button is added next to the datetime field with the ID of "clearDate". The following code is used to clear the "dueDate" field:

Code: Select all

$("#clearDate").click( function() {
   $("[id='form[dueDate]']").val('');
   $("[id='form[dueDate_label]']").val('');
   getFieldById("dueDate").model.attributes.data.label='';
   getFieldById("dueDate").model.attributes.data.value='';
})
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

ekaboom
Posts: 95
Joined: Tue Sep 11, 2012 12:34 pm

Re: Clearing a datetime field

Unread postby ekaboom » Thu Feb 02, 2017 11:50 am

Is there a way to clear a date area inside of a grid?

I've got some caculations going on inside my grid, one of which checks to see if the start date isn't after the end date.

Since I also need the date range number, so I just added an alert if dateRange < 0

But I'd also like to clear the rangeEnd number so they have to put it in again.

Since this doesn't work

Code: Select all

      rangeEnd = '';


Is there an alternative I could use to remove the rangeEnd value inside of a grid
(I removed all the other variables to try to make it clear)

Code: Select all

$("form").setOnchange(function(field, newVal, oldVal) {
  var totalRows = $("#grid0001").getNumberRows();
  for (var i = 1; i <= totalRows; i++) {
    rangeStart = moment($("#grid0001").getValue(i, 1));
    rangeEnd = moment($("#grid0001").getValue(i, 2));
    dateRange = rangeEnd.diff(rangeStart, 'days');

    //make sure the user entered valid values:
    if (dateRange < 0) {
      rangeEnd = '';
      alert('Start Date Is Before End Date.  Change The End Date/Start Date');
    }
    $("#grid0001").setValue(dateRange, i, 21);
  }
});

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

Re: Clearing a datetime field

Unread postby amosbatto » Thu Feb 02, 2017 4:45 pm

This bug is going to get fixed in the upcoming version 3.2, but if you want to clear the value in a datetime in a grid, then you need to do it this way:

Code: Select all

$("[id='[gridID][row-number][datetimeID]']").find("input").val('')


For example, in a grid with the ID 'clientsList' and a Datetime with the ID "dueDate", you can clear this datetime in the second row this way:

Code: Select all

$("[id='[clientsList][2][dueDate]']").find("input").val('')
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

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

Re: Clearing a datetime field

Unread postby amosbatto » Wed Aug 16, 2017 5:04 pm

This bug has been fixed in PM 3.2 and later. Now it is possible to clear at datetime field with this JavaScript:

Code: Select all

$("#mydatetime").setValue("");
where "mydatetime" is the ID of the datetime field.
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

markjustin
Posts: 1
Joined: Wed Jul 26, 2017 10:05 am
Country: Hong Kong

Re: Clearing a datetime field

Unread postby markjustin » Mon Aug 21, 2017 9:53 am

Thanks for giving such detailed information. I am really very comfused regarding this topic but my all confusions resolved. Please keep doing.


Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 1 guest