did You consider using JSLink? this is a kind of Javascript attached to a column which will be 'visible' in all forms (list view, edit form, add from, display form) where the column is present.
- You can add JSLink to column Via Powershell
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$web = Get-SPWeb "url"
$list = $web.Lists["listName"];
$field = $list.Fields.GetField("fieldName");
$field.JSLink = "/_layouts/15/examplefile.js"
$field.Update(true)
- or via c# which will be executed on feature active (very similar code to powershell)
please be aware that the JSlink may be stored under _layouts, or _catalogs or style library
like
~sitecollection/Style Library/JSFiles/File.js
other referent types are
- ~site – reference to the current SharePoint site (or “Web”)
- ~sitecollection – reference to the current SharePoint site collection (or “Site”)
- ~layouts – version specific reference to the web application Layouts folder (so it will automatically swap out /_layouts/14 or /_layouts/15 for you)
- ~sitecollectionlayouts – reference to the layouts folder in the current site collection (e.g. /sites/team/_layouts/15)
- ~sitelayouts – reference to the layouts folder in the current site (e.g. /sites/teams/subsite/_layouts/15)
then in this JSLink in on edit form You could add custom Javascript logic to make field readonly based on value from other column. The code should look like:
(function () {
'use strict';
var ctx = {};
function init() {
ctx.Templates = {};
ctx.Templates.Fields = {
'fieldName': {
'EditForm': ReadOnly
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
}
function ReadOnly(ctx) {
//console.log(ctx);
var val = ctx.CurrentFieldValue;
return "" + val + "";
}
init();
})();
I hope this will help :)