Setting Form Type

Hi,

Is it possible to 'switch' between display and edit forms with JS? I'd like to effectively replicate the 'Edit' button in the toolbar from a button on the form.

Thanks!

Hi @stevea,

You can use a button with this code to redirect the user to the edit form:

let listId = fd.spFormCtx.ListAttributes.Id;
let itemId = fd.itemId;
window.location.href = 'https://domain.sharepoint.com/sites/sitename/subsite/_layouts/15/listform.aspx?PageType=6&ListId=' + listId + '&ID=' + itemId;

Find more information about SharePoint links here:

@IliaLazarevskii Super! Thank you, works great!

One follow-up question. Is it possible to open a form with a particular tab index in focus?

Thanks!

Hi @stevea,

Sure! You can open a tab with JS at form render like this.

If you want to open different tabs depending on the redirect source, it's not that easy. Try saving the index to the browser's local storage before redirecting the user and reading it on form render to determine which tab to open. Here's how to work with local storage.

1 Like

Thanks! I'll take a look. I also wondered about perhaps adding a redirector parameter to the URL and reading that on form render, but not sure how SharePoint might react to an unknown parameter. One to test!