2

I have a list where some of the column names are very long because they contain question text for the user to answer in the field type element (choice, single line of text, etc). If I move the question text into the 'Description' property for the column I'll see it in EditForm and NewForm views, but I won't see it in DispForm view - and I really need to :(

enter image description here

Is there script I can insert on the DispForm.aspx page that will display the 'Description' property text there? Then I can just use column names like "Question #1" etc., and put the question text in 'Description' and it will be visible across all form views.

  • If one of the answers solved the problem stated in your question, you should mark this answer as accepted answer to help future visitors. – Mohamed El-Qassas MVP Jun 8 '17 at 23:55
1

Nice use of the CSR Venkat - I learned something.

The old fashioned way - you can use a REST call to get the list of fields for the list.

/SITENAME/_api/web/lists/getbytitle('LIST NAME')/Fields

Then loop through the d.results - there are attributes for the Description, and for each field with a description you could use the Title to match up with the display name of the field on the page, and append the information to the row .

An example:

<script type="text/javascript" src="/Javascript/JQuery/JQueryMin-1.11.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    displayDescriptions();
});
function displayDescriptions() {
    var options = "";

    $.ajax({
    url: _spPageContextInfo.webServerRelativeUrl +
    "/_api/web/lists/getbytitle('LIST_TITLE_HERE')/Fields" ,
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
     },
    success: function (data) {
        $.each(data.d.results, function(index, value) {
            if(value.Description != '') {
                $('h3:contains("' + value.Title + '")').eq(0).parents('tr:first').find('td').eq(1).prepend('<b>' + value.Description + '</b><br />');

            }
        });

     },
    error: function (err) {
        alert('Error in retrieving descriptions: ' + JSON.stringify(err));
     }
});
}


</script>
  • Hey! Wow! That works :) Okay, wondering if we can put the Description text above the user's answer (entry)? And, maybe add bold formatting to it so its clearly offset from the user's answer (entry)? – Dave Englund Jun 8 '17 at 22:03
  • I'll update my answer. You can add <b> </b> tags around the description, or <strong></strong> if that's your preference, And I think .prepend would work. Let me do a test and I'll update. – Robin in Or Jun 8 '17 at 22:18
  • I tried the following and it works well for moving above (with an extra line break to set answers/responses apart from questions): " .prepend(value.Description + '<br /><br />');" I'm still trying to figure how how to insert the bold tags though. LoL – Dave Englund Jun 9 '17 at 15:11
1

In the display form, you won`t get the field description which you can manage with simple javascript. But you can achieve using CSR (JS Link Concept).

Here is SharePoint column

enter image description here

Here is how I am displaying description in the Display Form

enter image description here

To achieve this the steps I have followed using below JavaScript

Code in my JavaScript File

SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
  Templates: {
    Fields: {
      'Question1': {
        DisplayForm: function(ctx) {
          return (ctx.CurrentFieldSchema.Description) + " - " + (ctx.CurrentItem.Question1);
        }
      }
    }
  }
});

Steps you have to follow to apply this script

  1. Upload your script file into one of your assets library.
  2. Go to your list item DispForm.aspx page and Edit the page.
  3. Edit web part properties.
  4. Under "Miscellaneous" section you have to refer the file path under "JS Link".
  5. Save changes.

The above is a sample I am using for my POC. You have to modify according to your requirement.

If you are new to the CSR you can refer this article for an additional explanation.

  • Use the Chrome Extension Cisar to WYSYWIG edit CSR files.. it does half the work for you.. including setting JSLinks – Danny '365CSI' Engelman Jun 8 '17 at 18:28
  • Your column name "Question 1" uses a space, but your code does not (''Quesion1'). Am I missing something? I've tried the column name both ways but to no avail. I took your script above and threw it into notepad, saved it as "JSScript-WrapColText.js" and loaded it to the sub-site Site Assets. Then I opened the form webpart on the DispForm.aspx page, and referenced the path in the JS Link as you instructed. Used a full URL (that ok?). Even so, no change. – Dave Englund Jun 8 '17 at 19:01
  • My Internal name is Question1 but display Text is Question 1. So in JavaScript always use Internal Name. – Venkat Konjeti Jun 8 '17 at 19:03
  • You can get the internal Name from the URL when you edit the field. – Venkat Konjeti Jun 8 '17 at 19:06
0

Looks like the Description is not outputted by the DispForm, so its not in the page, you would have to load it yourself (takes a lot of script)

Maybe add CSS to prevent your Question (Column Title) from getting to wide??

.ms-formtable > tbody > tr > td:first-child {/* first column */
    background: pink;
    width:100px;
}
  • I tried that by inserting it between a couple of script tages in a script editor webpart on the DispForm.aspx page, but unfortunately it had no impact in DispForm view. :( – Dave Englund Jun 8 '17 at 18:35
  • its CSS so needs STYLE tags – Danny '365CSI' Engelman Jun 8 '17 at 18:39

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.