0

I've created a spfx webpart on a list page in SharePoint 2016. After selecting items in the list I click a button which calls SP.ListOperation.Selection.getSelectedItems().

However, there is an eventlistener on the button added by SharePoint that deselects the items before I can get the ids. The click event looks like this:

body.ms-backgroundimage:http://av-dv/ScriptResource.axd?d=QlGFLwb4ffQZsPobR6ED1tzpe6s7gysC_vbFHz1hjBgqzuyVyzmWD9Lpsb2WPQkhZho-SjgwxKb4r9nHKqBm-N_dexDaGPS5gbkxoldei_v39JfFr9p2dCM9xo7KxdLH8BqYmwAqbEOf_MaidrarHCAVWU_vXSjblmxRNi3n4CBz80ji73a-Uao6iJGj9Qtg0&t=3d6efc1f.

It is visible using the devtools. How can I remove this event or better, how can I avoid the event bubble . I've tried e.preventDefault, e.stopPropagation() and return false. Removing the eventlistener manually using the devtool is the only way I can make it work.

1 Answer 1

0

Solution: convert button to input submit and wrap it in a form and add an onSubmit handler.

  <form onSubmit={this.handleSubmit}>
      <input type="submit" value="submit"/>
 </form>

 handleSubmit = (e) => {
     alert(SP.ListOperation.Selection.getSelectedItems().length);
     e.preventDefault();

  }

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.