LookUp Field – Retain Link as Read Only

Forums Dynamic Forms for SharePoint LookUp Field – Retain Link as Read Only

This topic contains 1 reply, has 2 voices, and was last updated by  Alexander Bautz 3 months, 4 weeks ago.

  • Author
    Posts
  • #20322

    Brandon W Green
    Participant

    Searched few quite a number of LookUp threads and was unable to find my solution, likely due to my ignorance and am hoping it is a quick fix.

    I have a LookUp column on my New Form that the user selects an ID from a secondary list. This creates the desired, linked touch point on the Display Form – however, I need this same link to be available on the Edit Form.

    Issue: I can bring the content in, but converting to Read Only removes the linked function of the LookUp content.

    Is there a way to display this link on the Edit form that I am completely overlooking?

  • #20333

    Alexander Bautz
    Keymaster

    When setting a lookup item as readonly in EditForm you only get the text and note the link. I have created a snippet you can use to hide the dropdown select and insert a link to the selected list item, but keep in mind that if you let the user open a child item, he might very well forget to save the changes in the original form.

    function getLookupItemLinkInEditForm(fin){
        var opt, id, title, url;
        opt = jQuery("#dffs_"+fin+" option:selected");
        id = opt.val();
        title = opt.text();
        url = "https://contoso.sharepoint.com/sites/thesite/lists/thelist/DispForm.aspx?id="+id;
        jQuery("#dffs_"+fin+" select").hide().after("<a style='cursor:pointer;' onclick='openLookupItemInDlg(\""+url+"\");'>"+title+"</a>");
    
    }
    
    function openLookupItemInDlg(url){
        SP.UI.ModalDialog.showModalDialog({"url":url,"dialogReturnValueCallback":function(a){
            if(a === 1){
                // Item was edited in the dialog
            }
        }});
    }
    
    getLookupItemLinkInEditForm("NameOfYourLookupColumn");

    Change “https://contoso.sharepoint.com/sites/thesite/lists/thelist” to reflect the path to the list where the lookup item is located.

    Alexander

You must be logged in to reply to this topic.