13

In my SharePoint Foundation I have an intranet with developed web parts, custom master page, etc. When I enter to a page with web parts (out of the box or developed) and I click on any space or I press the Enter key preferably in a input the page load in edit mode. I don't know if It is a feature of SharePoint or any other issue. Can you help me to identify the issue?

  • Use Chrome Browser Tool and find events listeners associated with KeyDown, KeyUp etc.. That will help to easily track down the root cause.. Also this not SharePoint feature. – Amal Hashim May 21 '15 at 12:01
  • @AmalHashim we have no event listeners associated with the input field. Still on enter SharePoint refreshes the page with edit mode. – Arsalan Adam Khatri May 21 '15 at 12:03
  • Can you check if current focus is in the edit page link or button. Also try to explicitly set focus on some other control and see if the issue persist. – Amal Hashim May 21 '15 at 12:04
  • Actually we have input field and we are entering text in it than pressing enter, so focus is on input field. The input field has submit event listener which submits the form. – Arsalan Adam Khatri May 21 '15 at 12:06
8

A workaround to the problem was to handle the Enter keypress event for the textbox via JQuery as follows:

$(document).ready(function () {

    $("#<%= TextBox1.ClientID %>").keypress(function (e) {

        if (e.keyCode == 13) {
            $("#<%= Button1.ClientID %>").click();
            e.preventDefault ? e.preventDefault() : e.returnValue = false;
            return false;
        }
    });

});
3

If you are using Publishing Pages. You can just simply hijack the offending javascript code and have them bend to your will.

<script>
    function WebForm_OnSubmit() {
        return false;
    }
</script>
  • One of these days I'll be smart enough to actually save the best fix for this (which is an event handler but there's something a little different about it that I can't remember.... none here quite get it right. That said, the above DOES fix it and is probably the best fix, provided you don't need to actually do a submit anywhere... – CeeMoney Jan 8 at 23:59
1

In case someone runs into the same problem I had where the other answers weren't working, the work-around I came up with is as follows,

I was using an <input> tag but replaced it with a <div contenteditable="true"> with the same classes as my input tag and then disabled the enter character with

input.keydown(function (e) {
    if (e.keyCode == 13) // enter key
        return false;
});

Hopefully this helps anyone with a similar problem.

0

Solution from Jouko Nyholm helped me https://social.technet.microsoft.com/Forums/en-US/33df42ba-00b3-41a8-8fb9-f8187cfc216d/strange-behavior-in-firefox-input-text-with-enter-opens-page-for-editing?forum=sharepointgeneralprevious

// SharePoint input element bug handler
// More bug: http://social.technet.microsoft.com/Forums/sharepoint/en-US/33df42ba-00b3-41a8-8fb9-f8187cfc216d/strange-behavior-in-firefox-input-text-with-enter-opens-page-for-editing?forum=sharepointgeneralprevious
// This fix stops form submit => blocks transfer to edit mode

var disableFormSubmitDueToBug = false;
var bugSubmitHandlerAttached = false;

$('*selector for inputs here*').keydown(function(e){
if(e.keyCode == 13 ) { 
  disableFormSubmitDueToBug = true;
  bindBugSubmitHandler();
} else {
  unbindBugSubmitHandler();
}
}).focusout(function(){
unbindBugSubmitHandler();
});

function bindBugSubmitHandler(){
$( "form" ).bind("submit", function( e ) {
if(disableFormSubmitDueToBug) {
e.preventDefault();
console.log('Blocked submit by SP bug handler');
}
bugSubmitHandlerAttached = true;
});
}

function unbindBugSubmitHandler(){
if(bugSubmitHandlerAttached){
$( "form" ).unbind("submit");
bugSubmitHandlerAttached = false;
console.log('SP bug submit handler unbind occurred');
}
}
</script>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.