How to hide sharepoint column fields on Display form?
-
20-01-2021 - |
Pregunta
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>
Solución
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:
Column hiddden:
Otros consejos
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" );
Licenciado bajo: CC-BY-SA con atribución
No afiliado a sharepoint.stackexchange