Welcome to the nuBuilder Forums!

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

If there are no entries in the subform - to hide the subform

Questions related to customising nuBuilder Forte with JavaScript or PHP.
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

If there are no entries in the subform - to hide the subform

Unread post by kknm »

If there are no entries in the subform - how to hide the subform ?
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: If there are no entries in the subform - to hide the sub

Unread post by kev1n »

Code: Select all

var subformId = 'accform'; // <--- replace with your subform object ID
if (nuSubformObject(subformId).rows.length < 2) {
  nuHide(subformId);
}
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: If there are no entries in the subform - to hide the sub

Unread post by kev1n »

Please let me know if the code works for you.
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: If there are no entries in the subform - to hide the sub

Unread post by kknm »

kev1n wrote:Please let me know if the code works for you.
Thanks, it works for me.
How would I apply this to all subforms on the main form at once without specifying the ID of each form?
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: If there are no entries in the subform - to hide the sub

Unread post by kev1n »

Call this function hideEmptySubforms() to hide all empty subforms

Code: Select all

function hideEmptySubforms() {
	nuSERVERRESPONSE.objects.map(item => {
	 
		if (item.type == 'subform') {
			if (nuSubformObject(item.id).rows.length == 1) {
				nuHide(item.id);
			}

		}
		
	})
}
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: If there are no entries in the subform - to hide the sub

Unread post by kknm »

kev1n wrote:Call this function hideEmptySubforms() to hide all empty subforms

Code: Select all

function hideEmptySubforms() {
	nuSERVERRESPONSE.objects.map(item => {
	 
		if (item.type == 'subform') {
			if (nuSubformObject(item.id).rows.length == 1) {
				nuHide(item.id);
			}

		}
		
	})
}
Unfortunately this doesn't work - nothing happens.
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: If there are no entries in the subform - to hide the sub

Unread post by kev1n »

How did you call the function and where?
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: If there are no entries in the subform - to hide the sub

Unread post by kknm »

kev1n wrote:How did you call the function and where?
hideSubForms.png
First I tried it without specifying a function, then I hung it up on the button of the main form through onclick.
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: If there are no entries in the subform - to hide the sub

Unread post by kev1n »

You need to call the function somewhere

Code: Select all

hideEmptySubforms();
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: If there are no entries in the subform - to hide the sub

Unread post by kknm »

kev1n wrote:You need to call the function somewhere

Code: Select all

hideEmptySubforms();
pusto.png
You do not have the required permissions to view the files attached to this post.
Post Reply