I am creating a sample form using Office UI Fabric components, I can see button component rendered but when I click on the button I get page posted back.

I have a simple html button as well but that works fine. Why post back happening with Fabric button only?

here is my code, I have added a content editor web part on my page and added this script init it. I have tried with visual web par as well but same result.

<link rel="stylesheet" 
js/1.4.0/css/fabric.min.css" />
<link rel="stylesheet" 
js/1.4.0/css/fabric.components.min.css" />
<script src="https://static2.sharepointonline.com/files/fabric/office-ui- 

<button class="ms-Button ms-Button--primary AlertExample">
   <span class="ms-Button-label">Create Account</span> 

<input type="button" name="name" value="HTML button" onclick="htmlclcik()" />

<script type="text/javascript">
var ButtonComponent = document.querySelector(".ms-Button.AlertExample");
new fabric["Button"](ButtonComponent, function () {
    alert("You clicked the Create Account button");
    return false;

function htmlclcik()
    alert("htmk click");

Update : This script is required to control this behavior.

var buttons = document.getElementsByTagName('button');
if (buttons && buttons.length) {
for (let i = 0; i < buttons.length; i++) {
    if (buttons[i]) {
        buttons[i].onclick = function () { return false; };

Try Adding type to button element as given below:

<button type="button" class="ms-Button ms-Button--primary AlertExample">
    <span class="ms-Button-label">Create Account</span> 

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.