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>

2 Answers 2

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

4
  • Thanks Jerry. I tried the above code you provided but its not working.
    – mdevm
    Commented Jul 27, 2018 at 14:00
  • What is you SharePoint version ? Above tested in SharePoint 2013 On-Premise.
    – Jerry
    Commented Jul 28, 2018 at 2:54
  • I am using SharePoint online
    – mdevm
    Commented Jul 30, 2018 at 1:50
  • Updated the code, please check, tested in SPO.
    – Jerry
    Commented Jul 30, 2018 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" );
5
  • 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
    Commented Jul 25, 2018 at 0:13
  • Unfortunately it did not work.
    – mdevm
    Commented Jul 25, 2018 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') ) Commented Jul 25, 2018 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
    Commented Jul 25, 2018 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
    Commented Jul 25, 2018 at 15:06

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.