0

We have some scenarios where it would be more reasonable for us to only use edit forms. For example when you click a link on a lookup column, I would like to get redirected to the edit form, and not the display form.

I tried to set

ctx.displayFormUrl = ctx.editFormUrl;

but it still redirects to display form. Does anyone have a solution for this?

1

Why not inject some simple javascript in a custom displayform, make it as the default, and do a simple redirection on the default form?

<script>
var newUrl = window.location.toString().replace("DisplayForm", "EditForm");
window.location = newUrl;
</script>
1

For the specific example you cite, clicking a link on a lookup column (presumably from a list view) and having that redirect to the edit form for the lookup item instead of the display form, I would think using Client Side Rendering to rewrite the link URL for the lookup field would be appropriate.

With a little research you can see that links to the display form look like

/_layouts/15/listform.aspx?PageType=4&ListId={list GUID}

and links to the edit form look like

/_layouts/15/listform.aspx?PageType=6&ListId={list GUID}

So really the only difference is the PageType.

Knowing that, your field override could look something like this:

function LookupFieldOverride (ctx) {
    // first let SharePoint render the default HTML for the lookup link 
    // so you get the correct syntax and List ID, etc.
    var renderer = new LookupFieldRenderer(ctx.CurrentFieldSchema.Name);
    var html = renderer.RenderField(ctx, ctx.CurrentFieldSchema, ctx.CurrentItem, ctx.CurrentListSchema);

    // then just replace the part of the URL that points to the display form
    // and make it point to the edit form instead
    var newHtml = html.replace(/PageType=4/g, 'PageType=6');
    return newHtml;
}
  • Hi. Thank you for your answer. I'm aware that the PageType defines which form it uses. I was hoping for a more global solution, to redirect all display forms to edit forms. This way it would be much more easy for us to maintain sites with many different forms and lists. I'm gonna do some research on Client Side Rendering – Chris May 9 '16 at 9:47

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.