You are viewing limited content. For full access, please sign in.

Question

Question

Reset date field on Form Reject

asked on May 20, 2020

I have an evaluation form where the user has to acknowledge that they have reviewed the form, then the system populates the subsequent name and date fields with the current user and today's date, respectively (Actually, the default value of the date field is captures on Form submission, which is what I want, but you get the idea).

Here's a visual:

The problem I have is that there is still one last chance for the document to be returned to an earlier state after this if some kind of error or problem is discovered.  Once the Confirmation Date, in particular, is set, I can't get it out!  So if the document gets returned for correction, when it gets back to this state, the Confirmation Date field is already populated with the old date, when it needs to revert back to it's original setting of capturing the date upon form submission, or at LEAST being reset with the date that the Form was loaded.

 

This is the javascript snippet I'm using that's triggered when the "Reject" button is clicked later:

      // Un-check the confirmation checkbox
      $('#Field323-0').attr('checked',false);
      $('#Field323-0').change();
      $('#Field328 input').val('').change();
      $('#Field333 input').val('').change();

The first two lines un-check the confirmation checkbox, then trigger the change so it gets saved.  That works fine.  The next two lines are where I have trouble.  I've tried without the Change, using "" instead of '', removing the "value" attribute entirely, using q333, or 'Field333' without the '#' character, using JS to reset the value to today's date manually... nothing is touching these values!!!

 

Can someone please help me see what I'm doing wrong?

Thanks in advance

0 0

Answer

SELECTED ANSWER
replied on May 20, 2020

Hi Sean,

Is your date field read-only? I've had issue in the past with changing the value of a read-only field.

If so, what you can do is remove it being read-only, then set the read-only with JavaScript. Then, when you ant to update the field with the current date, with JavaScript make it not read-only, change the value, and then read-only again.

Either like this, on form load:

$(document).ready(function() {
  var date = new Date();
  date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); //this ensures it's your local date and not GMT, since toISOString uses GMT
  var today = date.toISOString().substring(0, 10);
  
  $("#q333 input").val(today).change();
  $("#q333 input").prop("readonly", true);
});

Or when another field is changed:

$(document).ready(function() {
  $("#q333 input").prop("readonly", true);
});

$(document).on("change", "#q10 input", function() {
  var date = new Date();
  date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); //this ensures it's your local date and not GMT, since toISOString uses GMT
  var today = date.toISOString().substring(0, 10);
  
  $("#q333 input").prop("readonly", false);
  $("#q333 input").val(today).change();
  $("#q333 input").prop("readonly", true);
});

 

0 0
replied on May 27, 2020

Hi Blake,

This is along the right lines, so I marked it as the answer.  To be more complete, what I ended up having to do was un-mark the fields as "required" in the UI, then set them as read-only / disabled through javascript, then use javascript with a .change() function to save the changes upon rejection.  Thanks for the help Blake and Joseph!

0 0

Replies

replied on May 20, 2020

Hello Sean,

I didn't quite understand what are your intentions. Nonetheless, in order to change the value of the date field using jquery i use the following syntax:

$('.dateFieldClass .cf-field input').val('date'); 

in your case it is:

$('#Field333 input').val('date');

where date is the value of the date you want to set. Pay attention to respect the date format to avoid any inconsistencies. The date format is month/day/year by default. 

Hope i fulfilled your needs.

0 0
replied on May 20, 2020 Show version history

Hi Joseph,

The date value was entered previously, then the process was returned to an earlier step and when this form is revisited, the pre-existing date value needs to be updated to the current date.  My intention is to either:

a)  Remove the existing date value to return the field to it's default state (date captured on Form submission) or

b) If unable to do a, set the date value to today's date through JS

 

I agree that the code you put in SHOULD work, but the problem I'm having is that nothing I do changes that value.  I've checked and re-checked many times that I'm referencing the correct ID, but for example I just tried running this line:

$('#Field333 input').val('05/20/2020')

and then this line:

$('#Field333 input').val('2020-05-20')

based on the format of the field's min-max values, and I get nothing.  No change.  No errors in the developer console either.  I can't figure this out.

0 0
replied on May 20, 2020

Hey sean, 

 

First try to insert an alert() message if this line of code must be executed upon an event and check if this event is being triggered.

Also using the alert() in jquery try to find out if the selector is returning any sort of value before even trying to change it or setting it to empty just to make sure that your selector is correct. For example, type alert($('#Field333 input').val()); in the beginning of the jquery lines of code.

if the selector is correct, This must return the value of the date set in the previous form. Lets try to troubleshoot the problem.

let me know what happens.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.