1

I am having issues with textarea controls on InfoPath forms from SharePoint 2010 in the latest version of Google Chrome (52.0.2743.82 m).

One of the issues was with word-wrap (Multi line box Infopath not Word Wrapping in Chrome.). I posted a solution for that issue.

A new issue has come up where the Enter key will add a new line to the end of the text in the textarea instead of where the cursor was placed. I debugged the js files loaded with SharePoint down to these functions in core.js located in Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\INC.

TextBox.OnKeyPress = TextBox_OnKeyPress;
function TextBox_OnKeyPress(a, b) {
    ULSrLq: ;LeafControl_HideAsteriskAfterTyping(a, b);
    LeafControl.OnKeyPress(a, b);
    var c = Snippet_GetSnippetElementFromHtml(a);
    if (UserAgentInfo.strBrowser != 2) {
        if (TextBox_IsResizable(c))
            (UserAgentInfo.strBrowser != 3 || b.keyCode != 35) && TextBox_Resize(a)
    } else if (Util_KillEnterEvent(b))
        TextBox_IsMultiLine(c) && window.setTimeout("TextBox_InsertNewLine('" + a.id + "')", 1);
    else
        TextBox_IsResizable(c) && TextBox_Resize(a)
}
function TextBox_InsertNewLine(c) {
    ULSrLq: ;var a = document.getElementById(c);
    a.value = a.value + "\n";
    var b = Snippet_GetSnippetElementFromHtml(a);
    TextBox_IsResizable(b) && TextBox_Resize(a)
}

Chrome is detected as UserAgentInfo.strBrowser = 2.

I re-wrote the function as

 function TextBox_OnKeyPress2(a, b) {
    ULSrLq: ;LeafControl_HideAsteriskAfterTyping(a, b);
    LeafControl.OnKeyPress(a, b);
    var c = Snippet_GetSnippetElementFromHtml(a);
    if (TextBox_IsResizable(c))
        (UserAgentInfo.strBrowser != 3 || b.keyCode != 35) && TextBox_Resize(a)
}

and I set TextBox.OnKeyPress = TextBox_OnKeyPress2;

I tested this from the Developer Tools Console in Chrome. It appears to work though it needs more testing.

I can add the code to a js file that is loaded from the Site Master.

My questions are these:

  1. Has anyone else overridden core SharePoint js code? And is this acceptable to do it like this?
  2. Why was the original function processing input like this for Chrome?
1

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.