Forum Discussion
Can i set a field as Read-Only when editing a list item inside modern UI
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?
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
- john johnIron Contributor
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:-
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
I hope this helps.
Norm