Welcome to the nuBuilder Forums!

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

Beginners question: How to define a default value to a hidden textvalue?

Questions related to using nuBuilder Forte.
Post Reply
Espo
Posts: 5
Joined: Wed Jun 26, 2024 10:40 pm

Beginners question: How to define a default value to a hidden textvalue?

Unread post by Espo »

Hi
I'm trying to create a subform which sends some data to the database.
each row should contain a hidden field which contains the nuhash USER_TEAM Value.
How am I able to set the Input field hidden so that the rows contain automatically the value?

I thoud there is a input field class "hash_variable". (just a succesition)

If I'm on the wrong way, - how do I send hash_coockie values combined with the other fields to the database ?

Kind regards,
Michael
kev1n
nuBuilder Team
Posts: 4326
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 449 times
Contact:

Re: Beginners question: How to define a default value to a hidden textvalue?

Unread post by kev1n »

Hi Michael,

To populate a specific field in the subform with the user's team, use the JavaScript function nuUserTeam() in combination with the nuSetValue() function.

Let me know if you need an example.
Espo
Posts: 5
Joined: Wed Jun 26, 2024 10:40 pm

Re: Beginners question: How to define a default value to a hidden textvalue?

Unread post by Espo »

Yes, that way I tryed it and it works in a normal form, but how can I use it in subform?
There I only found the way of custom code of this field (onclick, or so) bit it didn't work until now.
I tried a Input field (Text) and custom code: nuSetValue('tra_mandant', nuUserTeam());
But then nothing happens.
kev1n
nuBuilder Team
Posts: 4326
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 449 times
Contact:

Re: Beginners question: How to define a default value to a hidden textvalue?

Unread post by kev1n »

Every subform field is composed of three parts:

1. Subform Object ID – e.g., mysubformId
2. Row number – a three-digit, zero-padded index (e.g., 000)
3. Object (field) Id – e.g., tra_mandant

Combined, a full field ID might look like: mysubformId000tra_mandant

To populate a field in the current subform row, add an afterinsertrow event to the subform and call

Code: Select all

subformAddUserTeam(event)
within it.

Declare this function in the form's Custom Code field

Code: Select all

function subformAddUserTeam(event){

       // retrieve the subform Object ID
	const sfId = event.currentTarget.getAttribute('data-nu-prefix').slice(0, -3); 
	
	// ID of the object whose value needs to be set (change this if targeting a different field))
	const objectId = "tra_mandant";

	// Value to assign (current user's team)
	const value = nuUserTeam(); 

	// Get the current subform row index
	rowIndex = nuCurrentRow();

	// Construct the full object ID for the target field
	const objId = `${sfId}${nuPad3(rowIndex)}${objectId}`;

	// Set the field value
	nuSetValue(objId, value);
}
Post Reply