I've tried and tried other options, and cannot come up with a solution to this one that actually works, so I wanted to put this one out there for help.
As the title describes, I'm trying to disable (not hide, but make READ-ONLY (but visible)) a couple of fields in my SP list Edit form. I need this to be done based on which permissions group the user is in. (i.e. - if they're NOT in the LEADERS group, the fields are READ ONLY. If they ARE in the LEADERS group, the fields are fully editable)
Here's the code I'm pounding over now:
<script>
function HideFields() {
//these are the fields in question. Origin is a single text line, Approved is a check box
fieldsToHide = ["Origin", "Approved"];
var formFieldTitles = $(".ms-formtable td.ms-formlabel h3.ms-standardheader");
formFieldTitles.each(function () {
var textToMatch = $(this).text();
var currentRow = $(this).closest('tr');
for (var i = 0; i < fieldsToHide.length; i++){
var field = fieldsToHide[i];
if (textToMatch.toLowerCase().replace("*", "").trim() === field.toLowerCase().replace("*", "").trim()){
$(currentRow).disable();
}
}
});
}
function AddToBodyOnLoad(){
_spBodyOnLoadFunctionNames.push("HideFields");
}
_spBodyOnLoadFunctionNames.push("AddToBodyOnLoad");