Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Hide individual form fields for users? Possible??

Questions related to using nuBuilder Forte.
Post Reply
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Hide individual form fields for users? Possible??

Unread post by Olikun »

Hi,

I have another question.
Sorry, my english is not good. I use the google translator :)

I have a form where my employees should enter data.

Can I hide individual form fields for some users?

The employees should not see all fields, only those in which they should enter something.


Many greetings
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Hide individual form fields for users? Possible??

Unread post by Janusz »

Hi,
You can use nuAccessLevelCode() or nuUserName() in JS to identify the user and use nuHide() with field id:

for example:
use in Form JS custom code:

Code: Select all

if (nuFormType() == 'edit') {
var usr=getUser();
if (!(usr=="admin" || usr=="Janusz"))
{nuHide('adm_links3');nuHide('adm_links4');}
}
---- define in header ----

Code: Select all

function getUser() {
   var user = nuUserName();
   if (user === '') { user = "admin";}
   return user;
}
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Hide individual form fields for users? Possible??

Unread post by kev1n »

Here's another code to hide certain fields if the Access Level code is "alcEmployee"

Add the code to your form's custom code

Code: Select all

// Declare the fields/nuBuider Object IDs here, that you want to hide
var fieldsToHide = 
	['cus_created_date', 
	'cus_created_user', 
	'cus_updated_date',
	'cus_updated_user'];

function hideFields(f, condition) {
    for (var i = 0; i < f.length; i++) {
         nuShow(f[i], ! condition); // (v4.5 specific)
    }
}

if (nuFormType() == 'edit') {
   hideFields(fieldsToHide, nuAccessLevelCode() == 'alcEmployee');
}
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Hide individual form fields for users? Possible??

Unread post by Olikun »

Hi,

Thank you, I think it's great how quickly you can get help here.
That's great.

I'll try it tonight
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Hide individual form fields for users? Possible??

Unread post by Olikun »

works perfectly, thank you very much
Post Reply