DavidLozzi / SharePoint-HideDisableFields

Lightweight JavaScript file to easily hide or disable fields on a SharePoint classic list form
MIT License
9 stars 4 forks source link

Cannot hide field if field title contains parentheses #6

Open sh67 opened 4 years ago

sh67 commented 4 years ago

Describe the bug When a field title contains a pair of parentheses, like Enter ABC (or DEF), the Fields.hide method does not work.

To Reproduce Steps to reproduce the behavior:

  1. Assign a field title containing a pair of parentheses, like Enter ABC (or DEF).
  2. Call the Fields.hide method on the field, like Fields.hide("Enter ABC (or DEF)").

Expected behavior The field should be hidden.

Desktop (please complete the following information):

Additional context I suspect it's falling down in the getCell method where the title is passed in as a regex pattern for matching, and the parentheses are being interpreted as a regex grouping. (When stepping through the code in the debugger, html comes back as null on this field.)

  getCell: function (fieldDisplayName) {
    var theCell = $(".ms-formbody").filter(function (i, o) {
      var rx = 'FieldName=\"' + fieldDisplayName + '\"';
       var html = o.innerHTML.match(new RegExp(rx));  <--- maybe here?
      return html !== null; // && html.length > 0;
    });
    return theCell;
  },

Workaround Currently I'm working around this by removing the parentheses from the field title.

Proposed Solution I apologize, but I should mention that I haven't given any thought as to what a solution might look like.