Can i set a field as Read-Only when editing a list item inside modern UI

Steel Contributor

I am working on a custom list inside SharePoint online classic team site. and i have a column of type Date named "OriginalApprovedDate". I want this column to be read-only inside Edit form while to have it editable inside Create/New form.

where i am using the modern UI, as in classic UI i can add a script editor web part and make the field Read-Only using a simple Jquery. but we can not do so in modern UI. also using PnP i am only able to hide the field inside the Edit form (but i do not have the option to set it as Read-Only),

$SiteURL = "https://******.sharepoint.com/sites/****"
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$fieldTitle = "OriginalApprovedDate"
$customfield = $Context.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle)
$customfield.SetShowInEditForm($false)
$customfield.SetShowInDisplayForm($true)
$customfield.UpdateAndPushChanges($true)

$Context.ExecuteQuery()

 

so can anyone advice on this please? how we can set a field as read-only inside an Edit form inside modern UI?

5 Replies

Hi @john john,

 

Have you considered customizing the form to set the OriginalApprovedDate field to readonly using PowerApps?

Capture.PNG

 

Specifically, set the control's DisplayMode to View (only displays data).

 

As a caution, users can still modify the OriginalApprovedDate field using Quick Edit. If you go the PowerApps route consider disabling Quick Edit for the list.

 

I hope this helps.

 

Norm

@Norman YoungThanks for the reply. Now i were trying to avoid using PowerApp for this simple scenario/requirement, i would use it for more complex scenarios if/when needed in the future. As using powerapp to create custom edit/new forms, means we have to live with these limitations (i am viewing things from the sharepoint point of view), compared to using the built-in modern Edit and New list forms :-

1. If we re-order the columns inside the content type, this re-ordering will not affect the power-app's custom Edit/New forms.

2. if i set a columns to be hidden on Edit and/or New forms using PnP,  this will not affect the cusotm powerapp edit form, for example this PnP script which will hide a column inside the Edit form while show it inside Display form, will be ignored by powerapp:-

$Context.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle)
$customfield.SetShowInEditForm($false)
$customfield.SetShowInDisplayForm($true)

 

So what i am trying to say, is that sometime we got new methods to implement things, but if we blindly follow these approaches (such as customizing the list's edit and new forms using powerapp), then we will loose many advantages of using sharepoint. where sharepoint should allow us to re-order the list fields from the content type and apply this to all the lists which use the same content type + the ability to control the visibility of the fields in New,Edit and Display forms using PnP and get the affect on all the list which uses the column, as so on.. i also remember when i wanted to use powerapp, i skipped this option because powerapp did not support external users accessing it.. so not sure if i have to live with all these limitations just to have a filed as read-only on edit forms... what do you think?

 

second question, to test things out, can you please advice what i need to do exactly inside powerapp to set the field as Read-Only inside the Edit form? as i did not find a way to change the DisplayMode to View, where when i click on the DisplayMode for the field i got a free text to enter a function as follow:-

displaymode123123.png

Hi @john john,

 

Question #1:

"... not sure if i have to live with all these limitations just to have a filed as read-only on edit forms... what do you think?"

 

That's a good question to ask but not one I can answer for you. If you assess the risk to value of the change for you and your end-users you will be in a better position to answer for yourself.

 

If it were my environment, I know my team could support the change and the customer could live with rework down the road should requirements or functionality change.

 

Question #2:

  • Edit the Card > click Advanced > click Unlock to change properties
  • Set DisplayMode = DisplayMode.View

1.png

 

2.png 

 

I hope this helps.

 

Norm

@Norman Youngthanks for the reply and help.i am not sure if i should follow the PowerApp appraoch.. there is a main issue in Office 365, is that things sometimes make you confused... we use sharepoint online because it support external sharing and managing the lists/fields through content types,, but if we start customizing our lists using PowerApp, then we will loose one of the main features found in sharepoint online, which is sharing with external users!!also we no more have control over the fields ...

 

second point. not sure about permissions for the app, will it get the same permission as the list? or it will be exposed to all users? so all users can view the create and edit powerapp forms? unlike the built-in forms which will only be exposed to the users who can access the underlying sharepoint list?

third point, i tried to create a simple powerapp form, where i set the field as read-only and i publish the app to sharepoint. but i have noted that lot of fields have lost their properties, for example i have a multi-line of text field (named Description), where it will be rendered as single line of text, and as a result we do not have the ability to add tables , images ,etc.. which is provided out of the box inside the sharepoint built-in list forms..

Hi @john john,

 

I believe that the customized form retains the same permissions as the underlying list. 

 

I can appreciate your point of view and concerns. I'm not certain how you make a column read-only without using PowerApps and disabling Quick Edit.  I'd be curious to hear what other's would do with this scenario.

 

Norm