Question

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

Was it helpful?

Solution

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
               }
           }
      }

    });
})();

OTHER TIPS

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.

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top