none
How to hide a few field in dispform.aspx in Sharepoint 2013 RRS feed

  • Question

  • Hi all,

    Did anyone know how to hide field in default dispform.aspx in Sharepoint 2013 using js or another tips? 

    I'm looking for that.. I don't why it's happen because if i use some js to hidden in new form or edit form it's work!

    Please help me 

    Thanks,

    Friday, March 16, 2018 9:09 AM

Answers

  • Hi,

    The following Script for your reference, add the code into script editor web part in the display form page.

    <script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {
    	$(".ms-standardheader:contains('FieldName')").closest("tr").hide();
    });
    </script>

    Best Regards,

    Unique


    • Edited by Unique_ Monday, March 26, 2018 2:35 AM
    • Marked as answer by Nhdy Monday, March 26, 2018 2:36 AM
    Monday, March 26, 2018 2:35 AM

All replies

  • Hi,

    One of the alternative is to use JSLink. There are many examples,

    1. http://sharepointandetc.blogspot.sg/2014/06/jslink-edit-and-new-form.html
    2. https://gudimanoj.wordpress.com/2017/05/02/using-js-link-to-customize-form-fields-on-new-and-edit-forms/ 


    Best regards,

    Riwut Libinuko
    Principal Architect, Singapore
    Office Servers and Services MVP | Singapore
    Blog : http://blog.libinuko.com

    Friday, March 16, 2018 9:24 AM
  • Hi cakriwut,

    It's doesn't work for me because the just only support newform.aspx and editform.aspx..

    But i want hide fields in dipsform.aspx.. Did you have any solution for that?

    Monday, March 19, 2018 1:07 AM
  • Hi Nhdy,

    i came a cross potential js script before for hiding fields from disform , here's full script 

    <script language="javascript" type="text/javascript">
    
    _spBodyOnLoadFunctionNames.push("hideFields");
    
    function findacontrol(FieldName) {
    
        var arr = document.getElementsByTagName("!");
        // get all comments
        for (var i = 0; i < arr.length; i++) {
            // now match the field name
            if (arr[i].innerHTML.indexOf(FieldName) > 0)
            { return arr[i]; }
        }
    }
    function hideField(fieldName) {
        var control = findacontrol(fieldName);
        if (control) {
            var parent1 = control.parentNode;
            if (parent1) {
                var parent2 = parent1.parentNode;
                if (parent2) {
                    parent2.style.display = "none";
                }
            }
        }
    }
    
    function hideFields() {
        hideField("AssignedTo");
        hideField("DueDate");
    }
    </script>

    have a look please on this similar question 

    https://sharepoint.stackexchange.com/questions/99013/how-to-hide-fields-on-customized-dispform-aspx-in-sharepoint-2010

    hope this will help you


    Best Regrads, Ahmed Madany MCTS @twitter http://twitter.com/ahmed_madany @Blog http://ahmedmadany.wordpress.com @LinkedIn http://eg.linkedin.com/pub/ahmed-madany/35/80/2b6

    Monday, March 19, 2018 6:04 AM
  • Hi Nhdy,

    You can run PowerShell command to hide the field in the display form in SharePoint 2013 Management Shell, check the demo below:

    $SPWeb = Get-SPWeb "http://spname";
    $SPList = $SPWeb.Lists["list name"];
    $SPField = $SPList.Fields["field name"];
    $SPField.ShowInDisplayForm = $false;
    $SPField.Update();
    $SPWeb.Dispose();
    

    Best regards,

    Grace Wang



    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, March 19, 2018 9:25 AM
  • Hi Nhdy,

    Please try below approach 

    1. Edit display form to add script editor web part with below script to hide the fields. Below script is to hide "Title" field. You can change field names as per your requirement.

        

    <script type="text/javascript">
    $( document ).ready(function() {
          $('.ms-formlabel').each(function() {
      if($( this ).text()=="Title"){
          $( this ).parent().hide();
       }
    });

    });
    </script>

    I hope it helps.

    Best Regards,
    Ramesh

    Monday, March 19, 2018 10:49 AM
  • Hi Nhdy,

    Is there any update?

    If the post helps you, you can mark it as answer to help other community members to find the information quickly.

    Best regards,

    grace Wang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, March 26, 2018 1:57 AM
  • Hi, it's not working fine to me..
    Monday, March 26, 2018 2:29 AM
  • Hi,

    The following Script for your reference, add the code into script editor web part in the display form page.

    <script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {
    	$(".ms-standardheader:contains('FieldName')").closest("tr").hide();
    });
    </script>

    Best Regards,

    Unique


    • Edited by Unique_ Monday, March 26, 2018 2:35 AM
    • Marked as answer by Nhdy Monday, March 26, 2018 2:36 AM
    Monday, March 26, 2018 2:35 AM
  • Hello,

    I have the following columns:

    Screen - Choice (Sim and Não)

    Screen Qtd - (0, 1, 2 and 3)

    Monitor1 - multiple lines

    Monitor2 - multiple lines

    Monitor3 - multiple lines

    And i want to display the columns ind Display View according with the choice.

    If Screen = Não, then all the columns are hide. If Screen = Sim, then show the column "Screen Qtd".

    Then if Screen Qtd=1, Monitor1 shows up and the others still hidden. and so on for the 2 and 3 options.

    I tried to do this code, but it only shows the Screen and Screen Qtd columns. What am i missing here or doing wrong?

    <script src="https://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    //Monitor
    if ($('.ms-standardheader:contains("Screen")').closest('td').next('td').text().indexOf('Sim') == -1)
    {
    $('.ms-standardheader:contains("Screen")').closest('tr').hide();
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else
    {
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    //Monitor Qtd
    if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('Sim') == -1)
    {
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('Sim') == 1)
    {
    $('.ms-standardheader:contains("Monitor1")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('Sim') == 2)
    {
    $('.ms-standardheader:contains("Monitor1")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('Sim') == 3)
    {
    $('.ms-standardheader:contains("Monitor1")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').show();
    }
    else {
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    });
    </script>

    Thank you!


    • Edited by JCVM35 Thursday, November 15, 2018 4:24 PM
    Thursday, November 15, 2018 4:21 PM
  • Hello,

    I have the following columns:

    Screen - Choice (Sim and Não)

    Screen Qtd - (0, 1, 2 and 3)

    Monitor1 - multiple lines

    Monitor2 - multiple lines

    Monitor3 - multiple lines

    And i want to display the columns ind Display View according with the choice.

    If Screen = Não, then all the columns are hide. If Screen = Sim, then show the column "Screen Qtd".

    Then if Screen Qtd=1, Monitor1 shows up and the others still hidden. and so on for the 2 and 3 options.

    I tried to do this code, but it only shows the Screen and Screen Qtd columns. What am i missing here or doing wrong?

    <script src="https://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    //Monitor
    if ($('.ms-standardheader:contains("Screen")').closest('td').next('td').text().indexOf('Sim') == -1)
    {
    $('.ms-standardheader:contains("Screen")').closest('tr').hide();
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else
    {
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    //Monitor Qtd
    if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('Sim') == -1)
    {
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('Sim') == 1)
    {
    $('.ms-standardheader:contains("Monitor1")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('Sim') == 2)
    {
    $('.ms-standardheader:contains("Monitor1")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('Sim') == 3)
    {
    $('.ms-standardheader:contains("Monitor1")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').show();
    }
    else {
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    });
    </script>

    Thank you!


    Solved it myself :)

    If you need or if it helps you, here it goes:

    <script src="https://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    //Monitor
    if ($('.ms-standardheader:contains("Screen")').closest('td').next('td').text().indexOf('Sim') == -1)
    {
    $('.ms-standardheader:contains("Screen")').closest('tr').hide();
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else
    {
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    //Monitor Qtd
    if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('1') != -1)
    {
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('2') != -1)
    {
    $('.ms-standardheader:contains("Monitor1")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    else if ($('.ms-standardheader:contains("Screen Qtd")').closest('td').next('td').text().indexOf('3') != -1)
    {
    $('.ms-standardheader:contains("Monitor1")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').show();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').show();
    }
    else {
    $('.ms-standardheader:contains("Screen Qtd")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor1")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor2")').closest('tr').hide();
    $('.ms-standardheader:contains("Monitor3")').closest('tr').hide();
    }
    });
    </script>

    Keep sharing and helping each other!

    Thursday, November 15, 2018 4:33 PM