Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

How to always show a default value in a select field Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
Paul
Posts: 27
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 9 times
Been thanked: 1 time

How to always show a default value in a select field

Unread post by Paul »

I have a select object on my edit form with 3 items in the list:

["item 1","item 2", "Item 3"]

What I need is to make 'item 1' be the default value shown/selected on the edit form regardless of whether it is a new record or not.

How do I accomplish this?
kev1n
nuBuilder Team
Posts: 4454
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 494 times
Contact:

Re: How to always show a default value in a select field

Unread post by kev1n »

One possibility is to add this JavaScript to the form's Custom Code:

nuSetValue('your_select_id_here','item 1');
Paul
Posts: 27
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 9 times
Been thanked: 1 time

Re: How to always show a default value in a select field

Unread post by Paul »

Perfect!

Thank you!
Paul
Posts: 27
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 9 times
Been thanked: 1 time

Re: How to always show a default value in a select field

Unread post by Paul »

The javascript works, but I need to do it only if it is a new record being created, and I also want to set two other select fields in a similar fashion.

I tried this javascript to accomplish that, but it does nothing, and no errors. What am I doing wrong?

Code: Select all

function nuFormAfterDisplay() {
    // Check if a new record is being created
    if (nuIsNewRecord()) {
        // Set the value of the select object
        nuSetValue('pk_finalDoughIngred1','sourdough starter');
	nuSetValue('pk_finalDoughIngred2','water');
	nuSetValue('pk_finalDoughIngred3','salt');
    }
}
kev1n
nuBuilder Team
Posts: 4454
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 494 times
Contact:

Re: How to always show a default value in a select field

Unread post by kev1n »

There is no nuFormAfterDisplay function in nuBuilder. Did AI come up with that?

Just place this in the form's Custom Code / Edit field:

Code: Select all

    if (nuIsNewRecord()) {
        // Set the value of the select object
        nuSetValue('pk_finalDoughIngred1','sourdough starter');
	nuSetValue('pk_finalDoughIngred2','water');
	nuSetValue('pk_finalDoughIngred3','salt');
    }
Paul
Posts: 27
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 9 times
Been thanked: 1 time

Re: How to always show a default value in a select field

Unread post by Paul »

Yes, Ai DID come up with that (grin). Thanks for the corrected code. Worked like a charm!
Post Reply