0
<div>
  <div>
    <fieldset>
      <div style="min-height: 600px;">

           <div class="row">

    <div class="col-xs-12">
      <div class="form-group">
        <label class="control-label" for="Order">Order<span style="color:red !important;">*</span></label>
        <input class="form-control" name="Order" id="sortOrder" type="number" placeholder="Order" ng-model="vm.sortOrder" autocomplete="off" required/>
      </div>
    </div>
    <br>  <br>
  </div>




      <div class="row"></div>  
    <div class="row">
      <div class="col-xs-12 form-group">

        <md-button class="md-raised md-primary" type="button" ng-click="vm.doSomeThing()">Do</md-button>

      </div>  
    </div>

    </div>
    </fieldset>
  </div>
  </div>

When i click do button. i want it to to fire doSomething and then come back to same place and do not submit form or change page. Even though i put type =" button" and not submit , it redirecting me away from the modal i am on. I don't understand why? I tried some solutions from this page Can I make a <button> not submit a form?... They did not work somehow

NoStressDeveloper
  • 491
  • 3
  • 9
  • 26

3 Answers3

1

You can use the 'preventDefault' event to stop the button from submitting. Use the fallowing for your reference. https://www.w3schools.com/jsref/event_preventdefault.asp

1

I see you are using Angular. I used simple JavaScript and HTML in this solution. You can modify to have your code return the proper boolean or just hard code a "return false" if you wish. The key element is the onclick clause: onclick="return doSomeThing();"

<script>
    function doSomeThing() {
        var shouldISubmit = false;
        return shouldISubmit;   // You can conditionally return true (submit) or false (do not submit)
    };
</script>

<form>
    <div class="col-xs-12 form-group">
        <button type="submit" onclick="return doSomeThing();">Do</button>
    </div>
</form>
George
  • 21
  • 4
1

Something completely unrelated happening in my project which is making the problem. There is a method which redirects it to a different page when i click submit. I just changed that method and now it does not post and returns to same page. This is very specific to my project.

NoStressDeveloper
  • 491
  • 3
  • 9
  • 26