I've got a list where I'm trying to modify the "+ new item" link at the top to point to a different form than the default for that list. (I realize I can change the default content type but that's not what I want to do .)

I'm using jQuery and my script is:

$(document).ready(function() {
    $("#idHomePageNewItem").attr("href", ".../_layouts/15/start.aspx#/Lists/Sandbox/NewForm.aspx?Source=.../Lists/Sandbox/AllItems.aspx&ContentTypeId=0x01080013D954563B0D1441BC90FAEC292D8798&RootFolder=/Lists/Sandbox");
    $("#idHomePageNewItem").attr("onclick", "");

(please ignore the "...")

I've gone in and edited the main web part on AllItems.aspx and added jQuery and my script into the JS link box, and it works when you initially click on the link to the list in the left-hand navigation, then click + new item. (I get the correct form.)

The problem is that after I've created a new item and it returns me to the list view, when I click + new item again, it sends me to the default content type instead of the one I want it to direct me to. Refreshing seems to fix it, but it doesn't always work.


I believe this is because an async postback is occuring, which refreshes the Add New link back to the original value.

To hook into the "after async" event, try the following:

    //TODO: rebind your jquery here

Sys.Application.add_load event details

EDIT: So the following does not work? Add a console.log to see if/when it fires.



function bindLink() {
     $("#idHomePageNewItem").attr("href", ".../_layouts/15/start.aspx#/Lists/Sandbox/NewForm.aspx?Source=.../Lists/Sandbox/AllItems.aspx&ContentTypeId=0x01080013D954563B0D1441BC90FAEC292D8798&RootFolder=/Lists/Sandbox");
     $("#idHomePageNewItem").attr("onclick", "");
  • This doesn't appear to work. – Eric D. Jun 21 '18 at 16:24
  • "(bindLink)"? Will I run into problems if I'm using jQuery 3.x? (I read bind has been deprecated.) – Eric D. Jun 21 '18 at 17:24
  • bindLink is just the name I gave the custom function, call it "setLinkToContentType" if you want ;) . I chose to extract the function since the binding logic is the same for both jquery and the "add_load" event. – Chad Jun 21 '18 at 17:33
  • Gotcha. Sadly this too didn't do the trick. Still reverts back to the original link after saving a list item. Refreshing goes back to my customization. – Eric D. Jun 21 '18 at 18:51
  • Correction: This works consistently after clearing my cache. =P – Eric D. Jun 21 '18 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.