0

I'm using sputility.js for making some fields as readonly in my new/edit forms. It works like a charm for all fields except Person fields. The issue with Person fields is when person fields became read-only they are displayed as a link with

<a href="/_layouts/15/userdisp.aspx?ID=<USER_ID_HERE>&amp;RootFolder=*"><USER_TITLE_HERE></a>

this used to throw me access denied error pages on clicking as i do not have access to root web.

I want the link to point to my site collection url something like

<a href="/sites/site_collection/sub site/_layouts/15/userdisp.aspx?ID=<USER_ID_HERE>&amp;RootFolder=*"><USER_TITLE_HERE></a>

which is the correct url to view the profile page.

1 Answer 1

0

I went through the sputility.js file and found this piece of code

 x.done(function (result) {
         // result is an SP.List because that is what we passed to resolve()!
         var htmlText = "";
         for (var i = 0; i < result.users.length; i++) {
            var user = result.users[i];
            if (htmlText !== "") { htmlText += "; "; }
               htmlText += '<a href="/_layouts/15/userdisp.aspx?ID=' + user.get_id().toString() + '&amp;RootFolder=*">' + user.get_title() + '</a>';
         }
         // finally! send the result to our callback
         return callback(htmlText);
      });

I modified the htmlText+= line to include the relative url of the current sub-site/site using _spPageContextInfo.webServerRelativeUrl thanks to this question and it works like i expected.

x.done(function (result) {
         // result is an SP.List because that is what we passed to resolve()!
         var htmlText = "";
         for (var i = 0; i < result.users.length; i++) {
            var user = result.users[i];
            if (htmlText !== "") { htmlText += "; "; }
               htmlText += '<a href="'+_spPageContextInfo.webServerRelativeUrl+'/_layouts/15/userdisp.aspx?ID=' + user.get_id().toString() + '&amp;RootFolder=*">' + user.get_title() + '</a>';
         }
         // finally! send the result to our callback
         return callback(htmlText);
      });

before i found this solution i was using something like this

var changeLink=function(){

                if($('div.sputility-readonly a').length ===1){
                    //console.log('href set. clearing interval');
                    clearInterval(timerInterval);
                    $('div.sputility-readonly a').each(function(){

                    var oldhref=$(this).attr('href');
                    //console.log(oldhref);
                    $(this).attr('href','/sites/site_collection/sub_site'+oldhref);
                    //console.log('new href '+$(this).attr('href'));

                    });
                }
                else{
                    //console.log('href not set yet');
                }
            };
timerInterval=setInterval(changeLink,100);

which i used to run whenever i make a Person field as readonly..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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