Problem with the .settab control

Hi.
Trying to figure out what I am missing here.

I am looking at the

fd.container('Tabs1').setTab(1);

to be able to control going to a specific tab. I have successfully added it to a button, and it will work and move it to that specific tab.

But I am having issues using the command in the following way.
I am looking to, when the form LOADS, to go to a specific tab.

My understanding, the same code should be placed within

fd.spRendered(function () {
});

But it does not change the tab when the page loads.
(actually upon checking, trying to say set a value in there, does not work either)

Thank you for any help anyone can provide.

Hello @GDkitty,

Welcome to the Plumsail Community!

This code works on my form, it opens the second tab on form load:

fd.spRendered(function(){
    fd.container('Tabs1').setTab(1)
});

Not sure I understand what you are trying to do. Please share the code you are suing or export the form.

Here is the form. Tab collection Called Tabs1, with 4 tabs. This is under the NEW form view.

This is the current JS code for the page

/*****************************************************************************
The JavaScript code from this section will be executed while loading
the current form.

The following predefined variables can be utilized in the code:

fd          - instance of the current form
$           - jQuery object
Dialog      - object for opening and closing dialogs
spfxContext - current SharePoint context

PnPjs library
https://pnp.github.io/pnpjs/

sp    - sp object from PnPjs:
graph - graph object from PnPjs

Site  - Site function from PnPjs
Web   - Web function from PnPjs

==============================================================================
*/
fd.spRendered(function () {
    // This code is executed once the form is rendered

    fd.field("Title").value = "WAHOO!";
    
    
    fd.container('Tabs1').setTab(1);
   
});

fd.spBeforeSave(function () {
    // This code is exeuted before saving the form and
    // may return Promise. The saving does not proceed until
    // the Promise is resolved. If the Promise is rejected,
    // the saving interrupts. This is the appropriate place
    // for adding custom validation.

    // Prevent saving if Status is set to 'Resolved' but
    // Comments field is empty
    if (fd.field('Status').value === 'Resolved' &&
        !fd.field('Comments').value) {
        throw Error('Please leave a comment.');
    }
});

fd.spSaved(function (result) {
    // This code is executed after saving the form
});

*****************************************************************************/

Neither things under spRendered seem to execute. Does not change the tab, does not set the field value.

BUT setting that same code (the set field value and the set tab) in the button on the form, it does execute. It sets the field value, changes the tab.

It is as if the spRendered is not executing?

I was just an idiot :stuck_out_tongue:

The *********************** at the bottom were not deleted/commented out, and were causing it to fail to load.
Removed them an it works!

1 Like