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

Question

Question

how to hide section and related fields on form based on current user information on laserfiche forms in javascript

asked on April 17, 2014

 I am trying to have a form used different users, each user can edit or read his own information, in addition to there is a part is public information can be shared.

 

how to hide section and related fields on form based on current user information on laserfiche forms in javascript , i do not want to use fields rules.

 

please advise

 

Forms version :9.1.1

 

0 0

Answer

APPROVED ANSWER
replied on April 18, 2014

This is pretty straightforward. You'll need a field to capture the user's name (give it the name CSS class). Set this field's default value to one of the current user variables.

 

Arrange the fields that will be shown or hidden based on the user into sections and give these sections reasonable CSS class names that you can reference later (in my example, I named mine section1).

 

Here's the basic structure you'll use. Be sure to place everything inside your document.ready function, and then create an if/else block for each user you want to check for.

 

$(document).ready(function() {
  if ($('.name input').val() == "Eric") {
    $('.section1').hide();
  } else {
    $('.section1').show();
  }
});

Or you could do something even simpler.

$(document).ready(function() {
  $('.name input').val() == "Eric" ? $('.section1').hide() : $('.section1').show();   
});

 

Both examples run when the document loads. If the name field will change as the user fills in the form, you'll want to adjust the code so that it runs at the appropriate time.

1 0

Replies

replied on April 19, 2014

thanks a lot Eric

 

can i do the same using variable  to know current user instead of using fields ?? how can I know if the current users is the initiator ?

0 0
replied on April 23, 2014

The most straightforward way to do this is to create a few fields with these variables as their default values. Then, you'll compare the values (assuming that you're using the name and initiator CSS classes for the fields where you are storing the current user name and initiator name), like so:

 

$(document).ready(function() {
  $('.name input').val() == $('.initiator input').val() ? $('.section1').hide() : $('.section1').show();   
});

 

0 0
replied on November 18, 2015

Hi Eric,

 

I am attempting to use this and it is not working, can you look at it and tell me what I'm doing wrong.

 

0 0
replied on November 18, 2015

Hi Jessica,

There are a few things you would need to change if the intent is to show/hide the date field based on user input into the drop down field. Also, since it is a drop down field you're checking against, you need to use "select" instead of "input"

$(document).ready(function() {
  $('.operation select').on('change', function() {
    if ($(this).val() == "Retailers") {
      $('.dealer').hide();
    } else {
      $('.dealer').show();
    }
  });
});
1 0
replied on November 19, 2015

You're amazing.

Thank you,

Jessica

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

Sign in to reply to this post.