Search code examples
javascripthtmlangularjsng-submit

clear sorting button of ngtable is calling form submit


i am using ng-table inside a form.

    <form role="form" name="frmCommand"  class="formValidCommand" novalidate="novalidate" ng-submit="frmCommand.$valid && vm.saveCommandChanges()">

i have a clear sorting button on the table.

                <button ng-click="storeCommandsTableParams.sorting({})" class="btn btn-default pull-right">Clear sorting</button>

clicking this button is calling vm.saveCommandChanges() instead of clearing the sort.

any suggestions please?


Solution

  • Default type attribute value for button tag is submit, so when you click on it it will trigger its parent form's submit event which is captured by ng-submit directive. So try change it to button type so that submit event does not happen.

    ie.

    <button 
       type="button"
       ng-click="storeCommandsTableParams.sorting({})" 
       class="btn btn-default pull-right">Clear sorting</button>