1

I'm using SP 2013 and have a list, within the list is a field called TrainText1 - it provides a step of the training which is being signed off, so the users know what they are signing off against. There are also 'associated' fields, which are Date1 and Tick1, which capture the date the training was completed and a tick to confirm as done.

Here is the field definition: Training Text field

I don't want the field TrainText1 to be edited, it needs to be visible in the form, but set as read only. It's purpose is to describe the training that is being signed off.

I realise editing the html, making a custom form is possible, but I need to avoid doing this for the moment, since requirements (field typed, layout...) are changing quite frequently at this stage. Later on I will create a proper custom form. In the meantime I need to get a working form and capture some data.

TrainText field in new/edit form

1

If you want the text to be visible in the new and editform use the JSLink property and render the field as display form.

Here is the code for the js file you can link to:

(function() { 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({

      Templates: {

           Fields: {
               "TrainText1": {
                   EditForm: SPField_FormDisplay_Default,
                   NewForm: SPField_FormDisplay_Default
               }
           }
      }

    });
})();
  • Thanks Anders, this works perfectly. For the benefit of anyone else reading this, I thought I would add a note. I ended up needing 4x 'TrainText' fields, all of them the same read-only fields. I simply copied Anders' code from top to bottom and pasted it to make four copies. Then, of course, I renamed them "TrainText1", "TrainText2", "TrainText3" and "TrainText4". – Tally Jun 7 '18 at 10:37
0

You can write javascript code and place it in script editor webpart below the form webpart (while editing page in browser).

It would be like:

<script type="text/javascript">
    document.getElementById('ctl00_ctl40_g_6739e090_207d_4646_a456_ccf1ba78992d_ff41_ctl00_ctl00_TextField').readOnly = true;
</script>

Get input field id from html-code.

  • Hi Alex, thanks for the answer, I didn't attempt to use this in the end since Anders' answer worked for me. I do appreciate the answer though. – Tally Jun 7 '18 at 10:38
0

Another perspective would be to remove it from your New and Edit forms. It will still be visible in your display form, but never in your edit/new forms.

You can do that with PowerShell for instance

Add-PSSnapIn Microsoft.SharePoint.PowerShell -ea 0
$Web = Get-SPWeb <my-sharepoint-site>
$List = $Web.Lists["<my-list-display-name>"]
$Field = $List.Fields["<my-field-display-name"]
$Field.ShowInNewForm = $False
$Field.ShowInEditForm = $False
$Field.Update()
$List.Update() # Not sure if necessary

Hope this helps!

  • Hi Peter, thanks for the suggestion. I would like to keep the fields visible in the Display/Edit form, as they contain useful information for the users. – Tally Jun 7 '18 at 8:44

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.