Page 1 of 1
How to always show a default value in a select field
Posted: Tue Sep 09, 2025 9:16 pm
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?
Re: How to always show a default value in a select field
Posted: Tue Sep 09, 2025 10:09 pm
by kev1n
One possibility is to add this JavaScript to the form's Custom Code:
nuSetValue('your_select_id_here','item 1');
Re: How to always show a default value in a select field
Posted: Tue Sep 09, 2025 10:59 pm
by Paul
Perfect!
Thank you!
Re: How to always show a default value in a select field
Posted: Tue Sep 09, 2025 11:44 pm
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');
}
}
Re: How to always show a default value in a select field
Posted: Wed Sep 10, 2025 5:40 am
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');
}
Re: How to always show a default value in a select field
Posted: Wed Sep 10, 2025 5:57 am
by Paul
Yes, Ai DID come up with that (grin). Thanks for the corrected code. Worked like a charm!