0

I'm using SP2013 On-prem and have a list with various columns. I'm doing JavaScript injection on the Editform.aspx (through ScriptEditor web parts) and then overriding the 'Save' button behavior. One of the columns is a Peoplepicker that a user would fill in during edit (on Editform.aspx). When this item is saved, the value entered into the Peoplepicker is not retained (written to the content database). All other fields in the Editform are being saved (retained); only Peoplepicker fields are not being saved.

Also, the statement is always returning false:

if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')); return false;

Commenting out this line doesn't change the behavior.

For the sake of simplicity, I created test list with a simple case which also doesn't save the value in the people picker.

Has anyone experienced this behavior or know how to resolve it?

Example code:

$(document).ready(function () {
    var oldPostBackUrl;
    var currentSourceValue;
    var button = $("input[id$=SaveItem]");
    var newPostBackUrl;
    button.removeAttr("onclick");
    button.click(function () {
        if (true) {
            var elementName = $(this).attr("name");
            var aspForm = $("form[id=aspnetForm]");
            oldPostBackUrl = aspForm[0].action;
            currentSourceValue = GetUrlKeyValue("Source", true, oldPostBackUrl);
            newPostBackUrl = oldPostBackUrl.replace(currentSourceValue, encodeURIComponent(window.location.href));
            if (!PreSaveItem()) return false;
            if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostBackUrl, false, true));
        }
        else {

        }
    })
});
2
  • am also facing the same issue. can you tell whats WPQ2?
    – dasarp
    Commented Oct 24, 2018 at 13:10
  • I found that my issue was changing the rendering mode for the webpart from Standard Rendering to Server Rendering. Hope this helps you. Commented Oct 25, 2018 at 19:00

1 Answer 1

0

This line: if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')); return false; will always return false since you added a ; before the return false statement.

So either remove the ; or add curly braces { & } to ensure your code will always react like you want it to and avoid further issues if you happen to add another line for that if but forget to add the curly braces. I think adding the curly braces would be your best option.

$(document).ready(function () {
    // Your preceding code...

    if (!PreSaveItem()) {
        return false;
    }
    if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) {
        return false;
    }

    WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostBackUrl, false, true));
}
4
  • douvillema, I'd like to take this opportunity to slam myself for overlooking such an obvious error. Thanks. I apologizing for that.... Commented Dec 22, 2017 at 16:26
  • This is totally fine, this is the kind of things that we overlook when we are searching too far. You're not alone to have done this. I'm glad it could fix your issue! Commented Dec 22, 2017 at 16:34
  • I'm still having an issue with this although somewhat different. What @douvillema pointed out is correct, the line if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) is always true. Therefore WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostBackUrl, false, true)) never gets called so I don't redirect to newPostBackUrl. The peoplepicker fields get saved but now a different problem. Commented Jan 10, 2018 at 22:21
  • @user1513177, if you have a different problem, I suggest to create another question, unless it is directly related to this issue. Commented Jan 11, 2018 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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