Welcome to the nuBuilder Forums!

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

Default value on subform objects when form is saved Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
Costa
Posts: 39
Joined: Sun Aug 15, 2021 9:46 am
Has thanked: 11 times
Been thanked: 4 times

Default value on subform objects when form is saved

Unread post by Costa »

Good evening everyone,

forgive the beginner's question but I searched and didn't find what I need.

I have a form with a subform and I need that when I insert the form fields and save it, the subform first record is also saved and, if no values has been inserted in the subform record, i need to insert a default value in a lookup object and in a input object (number) of the subform.

Thanks for any tips
Costa
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Default value on subform objects when form is saved

Unread post by kev1n »

Add a function nuBeforeSave() in your form's Custom Code.

Example:

Code: Select all

function nuBeforeSave() {

    const subformId = 'mysubform'; // subform object id
    const lookupObjectId = 'mylookup'; //  Id of your lookup object
    const lookupValue = '6505159c7272cf6'; // Primary key of lookup value to be set

    const firstLookupObj = $('#' + subformId + '000' + lookupObjectId);

    if (firstLookupObj.val() === '') {
        firstLookupObj.val(lookupValue).addClass('nuEdited');
    }

    const numberObjectId = 'myinput'; //  Id of your input/number object
    const numberValue = '123'; // number value to be set

    const firstNumberObj = $('#' + subformId + '000' + numberObjectId);

    if (firstNumberObj.val() === '') {
        firstNumberObj.nuSetValue(numberValue);
    }

    $('#' + subformId + '000' + 'nuDelete').nuSetValue(false);

    return true;

}
Costa
Posts: 39
Joined: Sun Aug 15, 2021 9:46 am
Has thanked: 11 times
Been thanked: 4 times

Re: Default value on subform objects when form is saved

Unread post by Costa »

Thanks Kev1n,

always the top!

later i will try and i will be back to you

Costa
Costa
Posts: 39
Joined: Sun Aug 15, 2021 9:46 am
Has thanked: 11 times
Been thanked: 4 times

Re: Default value on subform objects when form is saved

Unread post by Costa »

Perfect!

It works like a charm at the first shot.

Thanks Kev1n!!

Costa
Post Reply