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

Question

Question

show/hide collection

asked on March 29, 2021

I need to hide a collection where their aren't any visible fields:

When any of the Pass/Fail fields are "FAIL", the collection for that device should show, but if their aren't any failures, the collection for that device shouldn't show.  Can I get rid of collection rows with the "X"s without having to manually click them?

0 0

Answer

SELECTED ANSWER
replied on April 13, 2021 Show version history

The code you posted before, only runs when the trigger field is changed.  You need to also run it when the form is loaded.

Give this tweaked version a try (Note: I didn't test this).

$(document).ready(function () {
  
  //Run the function when the form is first loaded.
  HideCollectionRows();
  
  //Run the function when any field with the trigger class is changed.
  $('.trigger').change(HideCollectionRows);
  
  //Reusable function that cycles through all rows in collection to determine if they should be hidden.
  function HideCollectionRows()
  {
    $('.myCollectionCheckField').each(function() {
      if($(this).hasClass('hidden'))
      {
        $(this).closest('div.form-q').addClass('hidden');
      }
      else
      {
        $(this).closest('div.form-q').removeClass('hidden');
      }
    });
  }
 
});

 

0 0

Replies

replied on March 29, 2021

FYI. I'm just using field rules to show/hide fields.

0 0
replied on March 29, 2021

I'm not entirely certain I understand from your post how your form is working, so I might be off-base here.  But if I'm understanding correctly, you might be able to use some Javascript like this.  This assumes the collection has a Class Name of myCollection and one of the fields that is hidden within the collection has a Class Name of myCollectionCheckField.  Whenever any changes are made to myCollection, it checks to see if each instance of myCollectionCheckField is hidden or not, and if it is hidden, it'll hide the whole row in the collection.

CSS: 

.hiddenField {display: none!important;}

 

Javascript:

$(document).ready(function () {
  
  $('.myCollection').change(function() {
    $('.myCollectionCheckField').each(function() {
      if($(this).hasClass('hidden'))
      {
        $(this).closest('div.form-q').addClass('hiddenField');
      }
      else
      {
        $(this).closest('div.form-q').removeClass('hiddenField');
      }
    });
  });
  
});

 

0 0
replied on March 30, 2021

Hmmm...  still not working.  I named my collection myCollection and one of the fields that is hidden myCollectionCheckField (copied from your script), but still giving me blank collection rows.  

 

 

0 0
replied on April 7, 2021

Hmmm... I'm still working on this and not getting it.  sad

0 0
replied on April 7, 2021

So, maybe I can explain this better.  The form is a second form of a process.  When, on the first form in the process, any of the Pass/Fail fields for a collection "row" are FAIL, then I want that row only to show in the second form of the collection, not all rows of the collection.  

0 0
replied on April 7, 2021

I got it!  The second form had the collection as all read only, so it won't "change"  I used a field that does change when the form loads as the "trigger" field and that made it so it does hide the collection rows that are not needed when the "myCollectionCheckField" is hidden.

$(document).ready(function () {
  
  $('.trigger').change(function() {
    $('.myCollectionCheckField').each(function() {
      if($(this).hasClass('hidden'))
      {
        $(this).closest('div.form-q').addClass('hidden');
          }
      else
      {
        $(this).closest('div.form-q').removeClass('hidden');
      }
    });
  });
 
});

0 0
replied on April 13, 2021

But it still has all of the collection rows when it saves to Laserfiche.  I need to figure out how to prevent that!  HELP?

0 0
SELECTED ANSWER
replied on April 13, 2021 Show version history

The code you posted before, only runs when the trigger field is changed.  You need to also run it when the form is loaded.

Give this tweaked version a try (Note: I didn't test this).

$(document).ready(function () {
  
  //Run the function when the form is first loaded.
  HideCollectionRows();
  
  //Run the function when any field with the trigger class is changed.
  $('.trigger').change(HideCollectionRows);
  
  //Reusable function that cycles through all rows in collection to determine if they should be hidden.
  function HideCollectionRows()
  {
    $('.myCollectionCheckField').each(function() {
      if($(this).hasClass('hidden'))
      {
        $(this).closest('div.form-q').addClass('hidden');
      }
      else
      {
        $(this).closest('div.form-q').removeClass('hidden');
      }
    });
  }
 
});

 

0 0
replied on April 13, 2021

Thanks.  I'll give this a try.

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

Sign in to reply to this post.