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

Question

Question

Possible Bug: Forms not saving values when a column is hidden on other rows

asked on December 10, 2018 Show version history

Hello,

I sometimes use field rules to hide/show columns in a table with the values being required when the field is visible. However, I recently discovered that these values are lost if there are any rows where the column/field is hidden.

If the field is required, the rule must be set to ignore the value of hidden fields or else the form will not submit, but it seems that the "ignore" action is being applied across the board instead of just for the hidden fields.

I'm not sure if this is a recent problem because I've been using this approach with several Forms since 10.1 or 10.2 and this specific issue has never come up before (We're currently running 10.3.1.635).

As an example, build a table with two columns, a Yes/No dropdown and a single line. Make both fields required.

Set a field rule that Shows the single line field when column 1 equals Yes, and set it to Ignore hidden values.

If you submit the form with all rows set to yes, it saves the value as expected, however, if even one row is set to no, it will cause the form to discard all of the column 2 values.

1 0

Replies

replied on December 10, 2018 Show version history

For anyone who may run into the same issue, I came up with the following workaround

  1. Change the Field Rule to "Save the data" when the field is hidden
  2. Set Backend Validation to "no validation" on the form
  3. Add a class called "optionalRequired" to the field in the table
  4. Add the following code to the form's JavaScript
$(document).ready(function(){
  $('.Submit').on('click',function(){
    $('.optionalRequired input:hidden').removeAttr('required').removeClass('old-required');
  });
});

The field rule change will ensure the value is saved, and the JavaScript will ensure that the hidden fields are excluded from the front end validation when the user submits the form.

2 0
replied on April 9, 2019

Jason, 

 

This sounds like a great fix for my same issue.  But i'm wondering what turning off "Backend Validation" would do to the rest of my form.  I have a considerable number of lookups and fields on my form and if it were to break any of it, it could spell disaster for the known world.

0 0
replied on April 9, 2019 Show version history

As an FYI, it looks like this may have been fixed in 10.3.1 Update 2 under item 113844

https://support.laserfiche.com/kb/1014017/list-of-changes-for-laserfiche-forms-10-3-1-update-2

UPDATE: This does not appear to resolve the issue described in my original post

0 0
replied on April 9, 2019

I tried saving the data on the field when hidden, but also set it to required, which was a business requirement by the client.  Unfortunately, when submitting with a mixture of data in the table (hidden and unhidden), Forms spit back an error stating a field did not have data when saving.  Still trying to find a workout around to the solution without leaving the column unhidden and setting required on the field through JS, but still nothing.

0 0
replied on April 9, 2019 Show version history

What version of Forms are you running?

EDIT: I just tested it and the issue is still present anyway, so the workaround is still necessary even with version 10.3.1.635

0 0
replied on April 9, 2019

The client is running 10.3.1.635.

 

Just to show what's happening, here is the mix.  The district line should have a PO # in that field but is not showing on submission.

 

If it's both District then it retains the values:

 

0 0
replied on April 9, 2019

Here is the response when testing with "Save the data when the field/section/page is hidden" is selected on the field in the Field Rules:

 

0 0
replied on April 9, 2019

That is caused by the backend validation. Backend validation sees the field as required despite it being hidden.

0 0
replied on April 9, 2019

Thanks, I figured that was the case.  Unfortunately I think there are too many fields dependent upon "Backend Validation" on the form that I can't turn this off.  I'm still trying to find out all that would happen if I turned this off for the form.

0 0
replied on April 9, 2019 Show version history

What fields would be dependent upon backend validation?

Realistically, the purpose of backend validation is just to catch anything that slips through the front-end validation on the form itself.

Ideally you would want to do as much as possible on the front end since back end errors force the user to go back and resubmit the form.

0 0
replied on April 9, 2019

If i'm understanding how "Backend Validation" works, there are some hidden fields that cause other Field Rules to occur on other fields. 

For example, if an account number is entered, the next hidden field will validate against a Lookup rule to return if the account number matches or not.  If it does not, then another field will show up as un-hidden returned a value "Unknown Account Number" from the same Lookup rule.

 

My interpretation of how it works would disable the back-end lookup?  If this is not the case, maybe it will be fine?  As I said, i'm still unclear on it. 

0 0
replied on April 9, 2019

So, I implemented my messy work-around without unhiding the column entirely.  The only thing though, I had to remove the "Required" option on the field in Forms and apply it through JS:

 

$('.others_table').on('change', '.others_pt select',  OthersPoNumber);
function OthersPoNumber(){
  $('.others_table table tr').each(function(){
    var pt = $(this).closest('tr').find('.others_pt :selected').val();
    if (pt = 'District') {
      $(this).closest('tr').find('.others_po input').attr('required', true);
    }
    else {
      $(this).closest('tr').find('.others_po input').removeAttr('Required');
    }
  });
};

Essentially, whenever the drop-down (others_pt) in the table (others_table) has a change and the selected is "District", then the input field "others_po" has the "Required" attribute applied to it, else it is removed.

0 0
replied on April 9, 2019

Lookups do not execute on the backend, they would run on the form itself, so you could configure it to validate the results before allowing submission.

If you have the hidden lookup field as required, then it may trigger an error in backend validation if it is not populated, but there are ways to make that happen on the form itself too.

1 0
replied on September 9, 2020

Jason, would your solution work with only step 1 and 4? If we don't want to disable the backend validation.

You are not allowed to follow up in this post.

Sign in to reply to this post.