0

My custom button is triggering events twice.

Custom button is in a content editor web part. It is supposed to set some fields value unique to submitting, then call the normal save function. Below is my setup.

Wiring up my Submit button (different than Save) to call fSubmit:

var bSubmit = $("input[id='kSubmit']");
  bSubmit.click(function () {
  fSubmit();
});

fSubmit sets some vals then clicks on the real Save button:

function fSubmit() {
      // set some field values here
      $("input[value='Save']").click();
    }

Noticed some quirks so put the following in PreSave:

function PreSaveAction() {
console.log("submitted");
return false;
}

In the console I can see my custom submit action is firing twice with each click.

Tried a few variations, no luck, still firing twice...

$("input[id='kSubmit']").on('click', function () {
  fSubmit();
  return false;
});

and

$("input[id='kSubmit']").unbind('click').bind('click', function () {
  fSubmit();
  return false;
});

Suggestions?

2
  • Try to use Script editor web part instead of CEWP
    – Raf
    Commented May 13, 2019 at 4:23
  • @BDC604 Are you clicking the Save button of New/Edit form as well? Commented May 13, 2019 at 5:43

1 Answer 1

1

I overlooked that there are 2 save buttons; one on the form and one on the ribbon. This javascript is effectively clicking both. To resolve, I changed the code as below.

$("input[value='Save']:first").trigger('click');
0

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.