Jump to content
Sign in to follow this  
TroubleShooter

Rules: How to hide Sections with required fields

Recommended Posts

Hi,

 

I was trying to implement Rules on a Submission Form DataPage and was trying to hide a Section with required fields. I was wondering why I can't do so until a Support person pointed out on an article that it is not possible to hide a Section if there are required fields inside it.

 

I was wondering if there is something JavaScript can do with this.

 

Thanks in advance.

 

Regards,

TroubleShooter

Share this post


Link to post
Share on other sites

Hi @TroubleShooter

 

You can to paste>modify this code in the Footer of your Submission Form (disable HTML Editor).

Virtual4 is a checkbox, but you may opt to use other field elements such as text fields. Just comment/uncomment the corresponding alternate lines.

 

<script>

  var cbx = document.querySelector('[id*=cbParamVirtual4]')
//var textbox = document.querySelector('[id*=InsertRecordmyField]')
  var tbl = document.querySelector('[id*=hideThisTable]')

//textbox.onchange = function(){
cbx.onchange = function(){
  
//if (textbox.value == "hidemyfield")
  if (cbx.checked == false)
    tbl.style.display = "none";

  else
   tbl.style.display = "block";
}

var event = new Event('change');
cbx.dispatchEvent(event)

</script>

 

Next thing is to wrap all the fields you wish to hide in 2 HTML blocks (Remember to disable HTML Editor from the Advanced tab).

*Note that it is able to span across sections.

HTML Block 1:

<table id="hideThisTable">
</table>

 

===============

 

TL;DR / Preview

image.thumb.png.04a5e1317aff3a49665a7302101f6ec8.png

 

Once your page loads, if you check/uncheck Virtual4, it should toggle showing/hiding what's sandwiched within the <table> tag.

 

Hope this helps.

 

Cheers!

DN31337

Share this post


Link to post
Share on other sites

First .. if you hide REQUIRED fields, then your form may never get submitted, as there could be a situation where they're not displayed. - That's why it's not something which is done.

 

For your situation - the fix is super easy.

(1) Create a checkbox/button in the form named "section2btn" or whatever you want (it can be virtual or part of your table)

Example:  Show More Questions:   [    ]  Yes

(2) Below the above checkbox -> Create a section (example "SECTION2") with your specific form questions applied to it - the ones you wish to hide and have required.

Example:
SECTION2

-Q1
-Q2
-Q3

(3) Once you're done with all of your questions - make none of them required - then go back and select your check box above (named "section2btn") and create 2 rules for it.

(3a) Create Rule #1

Example:

Criteria   line_separator.gif?a=16.0
"section2btn" is not checked
Actions   line_separator.gif?a=16.0
Make Section2 hidden
 

(3b) Create Rule #2

Example:

Criteria   line_separator.gif?a=16.0
"section2btn" is checked
Actions   line_separator.gif?a=16.0
Make Q1 required
Make Q2 required
Make Q3 required
 
That should work for you.
 
Best,
 
Geoff

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...