How to Disable md-button

15.9k Views Asked by At

I have a form(HTML) and a directive to do stuff when submit button is clicked.The form has 10 input fields. The requirement is to keep the submit button which is a disabled till the time user enters value in at least one field.

Can anyone please help me. Iam new to angular and could not find much help.

2

There are 2 best solutions below

2
atinder On BEST ANSWER

simply use ng-disabled="true".

declare a function in your controller something like

checkInputFields which return either true or false depending on the form modal.

then use

<md-button ng-disabled="checInputFields()">
  Submit
</md-button>
5
Mohan Singh On
  <form ng-submit="search()" name="searchSideNav">
    <div layout="column" layout-align="center">
      <md-input-container flex>
        <label>{{::labels.documentName}}</label>
        <input ng-model="searchItems.sDocumentName" ng-required="" name="sDocumentName">
        <div ng-show="searchSideNav.sDocumentName.$invalid && !searchSideNav.sDocumentName.$pristine">
          <p ng-show="searchSideNav.sDocumentName.$error.required" class="help-block">Document is required</p>
        </div>
      </md-input-container>
       <md-button ng-disabled="searchSideNav.$invalid">
         Submit
      </md-button>
    </div>
  </form>