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

Question

Question

Make fields not required if collapsed section

asked on March 27, 2018 Show version history

Good morning,

I've been trying to find a good way to have a Section begin as Collapses with fields in it. I was wondering if someone has tried making the fields inside of the section to be non-required if the section is collapses and vice-versa.

I could try triggering some events with javascript to toggle between required and non-required but I was hoping that here was something easier, similar to when you show/hide a collection with Field Rules.

Any ideas? Suggestions?

Thank you,

Raul Gonzalez

section.PNG
section.PNG (5.14 KB)
0 0

Answer

SELECTED ANSWER
replied on March 27, 2018 Show version history

Raul,

The built-in field rules to show/hide fields will allow required fields to be ignored as long as you have back end validation disabled.

As a result, I think the best way to accomplish your goal would be to do the following:

  1. Create an Always Hidden "trigger" field for each Section (you might want it set to save these values if this is a multi-step process).
  2. Add a JavaScript event to the "collapse/expand" button (not actually a button element) that will change the value of the "trigger" field based on whether or not it has the "collapsed" class.
  3. Apply a Field Rule that will Hide the desired fields based on the value of the "trigger" field

 

I tested this out and it worked as expected. I added a custom CSS class to the target section and the associated trigger field:

  • Trigger -> Trigger1
  • Section -> Section1

 

Then added the following JavaScript code

$(document).ready(function(){
  $('.Section1 .collapsible').click(
    function(){
      if($(this).hasClass('collapsed')){
        $('.Trigger1 input').val('SHOW').change();
      }
      else{
        setTimeout(function(){
          $('.Trigger1 input').val('HIDE').change();
        },250);
      }
    }
  );
});

The Field Rule is set to Hide Field1 and Field2 and ignore the values when Trigger1 = "HIDE"

Hiding the fields as soon as the collapse button is clicked made the collapse animation a bit jerky, so I wrapped that part of the code in a setTimeout to allow the collapse animation to finish before actually hiding the fields.

1 0

Replies

replied on March 27, 2018

UPDATE: I added a Custom HTML field and added some text like <span class="someText">Some Text</span>

Then when I trigger the Expand/Collapse I check if the "someText" is visible and based on that I want to make required/non-required but can't get passed the visible/non-visible. The script always finds it visible.

 

Doesn't Work

  $(document).on('click', '#q1 .collapsible', chkFields);
  
  function chkFields() {
    
      if ( $('.someText').css('display') == 'none' ){
		alert('test');
}
    else
    {
      alert('dif alert');
    }
   

  }

 

Doesn't Work

  $(document).on('click', '#q1 .collapsible', chkFields);
  
  function chkFields() {
    
     if ($('.someText').is(':visible')) {
		alert('test');
}
    else
    {
      alert('dif alert');
    }
   

  }

 

0 0
replied on March 27, 2018

Jason,

I tested it and this worked really great. Now we can make the Sections fancier! Thanks!

Thank you,

Raul Gonzalez

0 0
replied on March 27, 2018

Jason,

I'm running into an issue that only seems to happen when you use radio buttons and a formula.

Example of what I have is:

  • One Single Line for Show/Hide value
  • One Section
  • Once Collection inside of the section
  • One radio button with value 1,2,3 and variable Radio_Button1 inside the collection
  • One Single Line with a function to sum the radio button as =SUM(Collection.Radio_Button1) inside of the collection

 

When I have this setting the "required" part still makes the field radio button required, even when section is collapsed.

It will work if I remove the formula or if I use a Textbox instead of a radio button to set the value.

Any idea on why it does not work with radio buttons and formulas? Below is a screenshot

Section1.PNG
Section1.PNG (22.9 KB)
0 0
replied on March 27, 2018

Formulas can be a bit tricky in these situations, but as a follow up question, are your field rules hiding the fields themselves, or the Collection as a whole?

0 0
replied on March 27, 2018 Show version history

Thanks Jason,

The field rule hides the Collection as a whole; but the same behavior is found if I hide the fields individually.

Rule.PNG
Rule.PNG (18.36 KB)
0 0
replied on March 27, 2018

Okay, that narrows things down at least. So the next question is what is the exact behavior you are seeing?

For example, do you get an error, or does it just prevent you from submitting the form?

If it is the latter, double check that you have "backend validation"set to "no validation" in the form settings (the gear icon in the top right when you are editing the form).

0 0
replied on March 27, 2018 Show version history

The form only prevents from submitting, and only when using radio buttons in a collection to calculate for some reason.

I set the form to "no validation" but get the same thing.

 

ErrorShow.PNG
ErrorShow2.PNG
ErrorShow.PNG (10.36 KB)
ErrorShow2.PNG (24.51 KB)
0 0
replied on March 27, 2018 Show version history

Is your field rule set to save or ignore the values of the fields? I would also flip it around and use HIDE when, instead of SHOW when; this could prevent unexpected behavior if the form loads and that trigger field is empty but the section is expanded.

0 0
replied on March 27, 2018

Right now it's set to "Ignore the data when the filed/section/page is hidden". I tired the other choice as well, but got the same results so I put it back to "Ignore..."

Rule1.PNG
Rule1.PNG (10.79 KB)
0 0
replied on March 27, 2018 Show version history

One question, why are you using a SUM function with the Total field as part of the collection? If it is within the collection, it is going to repeat the same value over and over because each one will add ALL of the radio button selections.

0 0
replied on March 27, 2018

Yes, I've been trying to get the fields out of the collection for somehow I can't make it work as I have the need to use "=SUMIF".

When I get it out of the collection, the SUMIF Function does not work. In reality I only need one set of fields, so I have set to a Fix Number of Sets to 1. The fields wouldn't repeat, but it's the only way I can make the SUMIF work. 

I also posted a question regarding that issue a few minutes ago. Here: https://answers.laserfiche.com/questions/138714/SUMIF-does-not-work-outside-of-Collection

UPDATE: I see that I got a reply from you on that. Let me try it. I agree that it would be better outside of the collection.

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

Sign in to reply to this post.