Welcome to the nuBuilder Forums!

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

Set default values in form

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Set default values in form

Unread post by treed »

Hello All, I've followed the video tutorial on the subject and when a new record is added the correct default value shows in the select box. However when the record is saved the new value is null. Here's my code.
if(nuIsNewRecord()){
$('#OutContidion').val(1).change;
}

The value 1 has the word New attached to it and New is what is shown in the selection box. Anyone have an idea what the issue might be?
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: Set default values in form

Unread post by treed »

Additional info, even selecting the "New" value from the select box does saves a null value. If the record is edited the chosen value does save.
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Set default values in form

Unread post by kev1n »

The syntax is wrong

Code: Select all

$('#OutContidion').val(1).change()
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: Set default values in form

Unread post by treed »

Thanks! sometimes another set of eyes helps. Added the () and all works. And now when I go to leave the page I've got to cancel the changes because the code starts the edit process. Perhaps that code can go under a different event. Looks like it would need to be PHP to do that though.
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Set default values in form

Unread post by kev1n »

treed wrote:And now when I go to leave the page I've got to cancel the changes because the code starts the edit process. Perhaps that code can go under a different event. Looks like it would need to be PHP to do that though.
Add nuHasNotBeenEdited(); after changing the field.
Wiki wrote:This will set the status of an Edit Form to not Edited and do 2 things

The Save Action Button will return to its normal color.
The web browser will not alert the user when leaving the current record.

Code: Select all

if (nuFormType() == 'edit') {

   $('#OutContidion').val(1).change();
   nuHasNotBeenEdited();
}
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: Set default values in form

Unread post by treed »

Again, Thank you very much. Is there a reference somewhere for all these nice JavaScript functions???
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Set default values in form

Unread post by admin »

Post Reply