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?

  • Try to use Script editor web part instead of CEWP – Raf May 13 at 4:23
  • @BDC604 Are you clicking the Save button of New/Edit form as well? – Sohail Shaikh May 13 at 5:43
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');

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.