Page 1 of 1

[SOLVED] how to clear datetime field

Posted: Tue Apr 12, 2016 8:31 am
by awisla
Hello,
How to clear datetime field by javascript:
Simple
$('#var_hourFrom').setValue('');
$('#var_hourFrom').setText('');
does not work as date format is required.

Thank you for help.
Adrian

Re: how to clear datetime field

Posted: Tue Apr 12, 2016 12:23 pm
by PaolaPellegrini
Try using JQuery please

$("#form\\[datetimeVar\\]")[0].value = '';

I hope your comments

Re: how to clear datetime field

Posted: Tue Apr 12, 2016 1:44 pm
by awisla
Hello,
Thank you for help. It is working as required.

Regards
Adrian

Re: [SOLVED] how to clear datetime field

Posted: Wed Apr 27, 2016 7:00 pm
by amosbatto
I filed a bug report about this: https://processmaker.atlassian.net/browse/TRI-1280
Until this gets fixed, you should use this JavaScript code to clear datetime controls:
Code: Select all
$("#form\\[mydate\\]").val('');
$("#form\\[mydate_label\\]").val('');

Re: [SOLVED] how to clear datetime field

Posted: Thu Oct 27, 2016 4:12 am
by Margrate
Hello Amos,

The given JavaScript code to clear datetime controls is working fine. But when we want to check the mandatory of the same datetime control based on conditions the value still exists at the backend so it is not checking the mandatory of the field.
Please find the attached .json.

Please help us on this.

Re: [SOLVED] how to clear datetime field

Posted: Thu Oct 27, 2016 5:59 pm
by amosbatto
The problem is that the selected data is still in the model information for the field and I don't know how to set this. You can use setOnSubmit() to check whether the field is empty and display an alert to the user, like this:
Code: Select all
$("#clearDate").click(function() {
   $("#form\\[eventDate\\]").val('');
   $("#form\\[eventDate_label\\]").val('');
});

getFormById('64428352758068d2fe4eb97051094686').setOnSubmit(function() {
 if ($("#form\\[eventDate\\]").val() == '') {
    alert("Please set an Event Date.");  
    return false; //stop submit
  }
});
Where '64428352758068d2fe4eb97051094686' is the UID of the DynaForm, and eventDate is the ID of the date field and clearDate is the ID of the button to clear the date field.

Re: [SOLVED] how to clear datetime field

Posted: Mon Oct 31, 2016 12:54 am
by Margrate
Hello Amos,

Thanks for the workaround. Please let us know if this is possible in upcoming versions.


Regards,
Margrate

Re: [SOLVED] how to clear datetime field

Posted: Mon Oct 31, 2016 6:47 pm
by amosbatto
I filed a bug report about this, but the developers responded that the fileupload in version 3.1 allows a user to delete selected files. If you only want one file to be uploaded, you can use javascript to limit it with fileupload.

Re: [SOLVED] how to clear datetime field

Posted: Mon Jan 09, 2017 3:35 am
by adijadhav
Dear hii,

Above function Clears a date but when i fire sql trigger to it ,it show date in databse.

Re: [SOLVED] how to clear datetime field

Posted: Mon Jan 09, 2017 9:47 pm
by amosbatto
I found a solution in the JavaScript:
Code: Select all
$("#clearDate").click(function() {
   $("#form\\[dueDate\\]").val('');
   $("#form\\[dueDate_label\\]").val('');
   getFieldById("dueDate").model.attributes.data.label='';
   getFieldById("dueDate").model.attributes.data.value='';
});
where "clearDate" is the ID of the datetime control and "clearDate" is the ID of a button.