1

I am using below code to hide a field on SharePoint display form but unfortunately its not working. Can someone please help me correct it, thanks in advance.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(init,'sp.js');
function init(){  
$('nobr:contains("Resubmit for Approval")').closest('tr').hide();
}
</script>
1

Replace the Jquery selector for the column needs to be hidden in display form like below:

 <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">

    $( document ).ready(function() {
        $(".ms-standardheader:contains('Resubmit for Approval')").closest("tr").hide();

    });
    </script>

Original:

enter image description here

Column hiddden:

enter image description here

  • Thanks Jerry. I tried the above code you provided but its not working. – mdevm Jul 27 '18 at 14:00
  • What is you SharePoint version ? Above tested in SharePoint 2013 On-Premise. – Jerry_MSFT Jul 28 '18 at 2:54
  • I am using SharePoint online – mdevm Jul 30 '18 at 1:50
  • Updated the code, please check, tested in SPO. – Jerry_MSFT Jul 30 '18 at 7:23
2

Normally your code would be in this order:

function init(){  
   $('nobr:contains("Resubmit for Approval")').closest('tr').hide();
}
ExecuteOrDelayUntilScriptLoaded(init,'sp.js');

Your problem is most likely due to waiting for other things:

  • The jQuery library to load from the external CDN.
  • Other SharePoint libraries.
  • The creation of the elements in the form. (You did not say where you added your code.)

A more common way to delay the running of your code until after SharePoint content is loaded is to use a SharePoint array that behaves as a function loading queue.

function init(){  
   $('nobr:contains("Resubmit for Approval")').closest('tr').hide();
}

_spBodyOnLoadFunctionNames.push( "init" );
  • I added script editor web part on display form and used this code:: <script type="text/javascript" src="code.jquery.com/jquery-1.12.4.js"></script> <script type="text/javascript"> function init(){ $('nobr:contains("Resubmit for Approval")').closest('tr').hide(); } _spBodyOnLoadFunctionNames.push("init"); </script> – mdevm Jul 25 '18 at 0:13
  • Unfortunately it did not work. – mdevm Jul 25 '18 at 0:13
  • Did you get an error? Any error in the F12 browser tools? What do you see with: alert( $('nobr:contains("Resubmit for Approval")').closest('tr') ) – Mike Smith - MCT - MVP Jul 25 '18 at 3:09
  • Mike, I received true when I ran the below code: function init(){ $('nobr:contains("Resubmit for Approval")').closest('tr').hide(); } ExecuteOrDelayUntilScriptLoaded(init,'sp.js'); – mdevm Jul 25 '18 at 15:01
  • Here is how field name appears on display form, as an anchor tag: <a name="SPBookmark_Resubmit_x0020_for_x0020_Approva"></a> – mdevm Jul 25 '18 at 15:06

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.