0

I am seeing JavaScript errors on the edit form of one of my tasks lists - see below. I have added my own custom JavaScript on this edit form.

This is in the Chrome browser. I haven't tested sufficiently in IE to know whether they say problem exists, but will be checking over the next couple of days. Regardless, these errors should not occurring in Chrome.

They are intermittent. If I hit F5 to refresh the page they disappear.

This is causing me problems because my custom JavaScript does not run when these errors occur.

What could be causing these errors?

Is there any way to prevent them, or to ensure my custom JavaScript always runs?

enter image description here

EDIT:

This is the JavaScript on the page:

var OPS_TASK_CT_ID = "0x0108003365C4474CAE8C42BCE396314E88E51F00FA61D6E4729D0144BCAE8455B51432E10038383AEC872F6F4E93CAD0A18A8F86C4",
    CHANGE_CONTROL_TASK_CT_ID = "0x0108003365C4474CAE8C42BCE396314E88E51F00391E64F7CAA8794CA403CF082A3CE05B003B7F30E720E93346BD28A966F89FE5FE",
    SECURITY_MANAGER_TASK_CT_ID = "0x0108003365C4474CAE8C42BCE396314E88E51F00B1D7302C0D705E4C8F15D473130B00F000A58ED3A3D435504081A7A23C05A67CD1";

_spBodyOnLoadFunctionNames.push("Init");

function Init(){
    // Check what content type this form is
    var ctVal = $("select[title='Content Type']").val();

    if (ctVal == OPS_TASK_CT_ID) {
        var fieldsToMakeReadOnly = [
            { title: "Server Name", type: "input" },
            { title: "Server ID", type: "input" },
            { title: "Server Location", type: "select" },
            { title: "Server Type", type: "select" },
            { title: "OS", type: "select" },
            { title: "Classification", type: "select" },
            { title: "Service ID", type: "input" },
            { title: "Recovery Documentation", type: "input" },
            { title: "Supported By SSC", type: "input" },
            { title: "Consistency Group", type: "input" },
            { title: "Change Reference Number", type: "input" },
            { title: "Decommissioned", type: "input" },
            { title: "Recovery Order", type: "input" }
        ];

        w_FixTaskEditForm();
        w_MakeFieldsReadonly(fieldsToMakeReadOnly);     
    }
    else if (ctVal == CHANGE_CONTROL_TASK_CT_ID) {
        w_FixTaskEditForm();
    }
    else if (ctVal == SECURITY_MANAGER_TASK_CT_ID) {
        w_FixTaskEditForm();
    }
}

These are the functions being called (in another JS file):

function w_MakeFieldsReadonly(fields) {
    var title;
    var type;

    for (var i = 0; i < fields.length; i++) {
        title = fields[i].title;
        type = fields[i].type;

        $(type + "[title='" + title + "']").attr("disabled", true);
    }
}

function w_FixTaskEditForm() {
    var title;
    var type;
    var fields = [
            { title: "Content Type", type: "select" },
            { title: "Task Name", type: "input" },
            { title: "Start Date", type: "input" },
            { title: "Due Date", type: "input" },
            { title: "Assigned To", type: "input" },
            { title: "% Complete", type: "input" },
            { title: "Predecessors possible values", type: "select" },
            { title: "Priority", type: "select" },
            { title: "Task Status", type: "select" }
    ];
    for (var i = 0; i < fields.length; i++) {
        title = fields[i].title;
        type = fields[i].type;

        $(type + "[title='" + title + "']").first().closest("td[class='ms-formbody']").parent().hide();
    }

    // Make the task description field read only
    $("[id^='Body_'][id$='_$TextField_inplacerte']").attr("contenteditable", "false");

    // Show the rest of the fields in the form (likely custom fields)
    if (typeof rlfiShowMore === "function") {
        rlfiShowMore()
    }
}
  • how did you implement your javascript into the form? – Gwny Apr 4 '16 at 8:54
  • I enter the location to my JavaScript files, stored in the Site Assets library, into the JSLink field of the form webpart. – Submits Apr 4 '16 at 9:05
  • is it a JSLink javascript file or normal javascript with someting like document.ready... ? – Gwny Apr 4 '16 at 9:19
  • If by "JSLink" you mean Client Side Rendering, no - it is not a CSR JavaScript file. I start my JavaScript file with _spBodyOnLoadFunctionNames.push("Init"); – Submits Apr 4 '16 at 10:00
  • At least the SAMEORIGIN error is always displayed when you save the page after editing. But it should disappear if you refresh (or browse to the page directly) so it shouldn't impact operation. If errors stay when you go to edit page directly, can you share the script mentioned ? – Charles Apr 4 '16 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.