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

Question

Question

Best method for js to determine if form is live or submitted

asked on February 5, 2019

Many times I find myself hunting for a field to check to see if it has a val() or text() so that javascript can determine if it is dealing with the live version of the form or the submitted version of the form.  I occasionally forget that my field that is calculated and/or populated from a change event won't be populated on the submitted form.  Instead of writing the javascript code all together, I then have to go back through and patch in some code to check if a .val() that should be populated is actually empty.  Then substitute in it's .text() equivalent.  

I would be interested in hearing if someone had a simple go-to method that you used on most forms...some kind of flag field that you could check easily to see which version of the form your js was dealing with.

 

0 0

Replies

replied on February 9, 2019

I'm not sure exactly what you're goal is for this, but if you're losing values on submission, then it sounds like you might be updating them with JavaScript, in which case you should trigger the change event after .val() to make sure Forms keeps it on submission.

For example, if I do the following

$('#Field1').change(function(){
    $('#Field2').val('Test');
});

Field 2 might lose it's value on submission because Forms doesn't know it was updated. However, if I trigger the change event after setting the value it will still be there in the next step.

$('#Field2').val('Test').change();

Another thing worth noting is that the built-in functions can handle a lot of calculations for you and they automatically trigger on field updates without requiring any extra JavaScript.

 

As far as tracking the difference between a submitted form and a new submission, an easy way is to add a date field that is set to use current date as the default and marked as read only (possibly even hide it if you'd like).

When you default a date field to the current date and make it read-only, it won't populate a value until submission so you could easily tell the difference between a "live" and "submitted" form.

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

Sign in to reply to this post.