1

I have form with input fields, radio buttons, select boxes. Need submit button make active after when all fields have a data. example my fields and button.

<div class="form-group" ng-class="{ 'has-error': myForm.birth.$touched && myForm.birth.$invalid }">
    <label class="col-sm-3 control-label">{{getWord('Dob')}}<sup>*</sup></label>

    <div class="col-sm-6">
        <p class="input-group">
            <input type="text" placeholder="1988-12-12" class="form-control" name="birth"
                   uib-datepicker-popup="{{format}}" ng-model="patient.DOB"
                   data-placeholder=""
                   is-open="isOpened" datepicker-options="dpOptions"
                   close-text="Close" alt-input-formats="altInputFormats" required/>

            <span class="input-group-btn">
                <button type="button" class="btn btn-default"
                        ng-click="openCalender()"><i
                    class="glyphicon glyphicon-calendar"></i>
                </button>
            </span>

        <p ng-show="myForm.birth.$error.required" style="color:red" ng-if="myForm.birth.$touched">Date of birth is
            required.</p>

        </p>
    </div>
</div>

and code button

<div class="form-group">
    <div class="text-center">
        <button class="btn btn-labeled btn-success" type="button" ng-click="makeAptmn()">
            <span class="btn-label"><i class="glyphicon glyphicon-ok"></i></span>

            {{getWord('makebutton')}}
        </button>
        <button class="btn btn-labeled btn-danger" type="button">
            <span class="btn-label"><i class="glyphicon glyphicon-remove"></i></span>

            {{getWord('clearbutton')}}
        </button>
    </div>
</div>

and need same for clear button, clear all input fields.

4

1 回答 1

0

只需将您的按钮代码修改为:

<button class="btn btn-labeled btn-success" type="button" ng-click="makeAptmn()"
     ng-disabled="myForm.$invalid">
      <span class="btn-label"><i class="glyphicon glyphicon-ok"></i></span>

      {{getWord('makebutton')}}
</button>

我添加ng-disabled="myForm.$invalid"了当任何输入字段无效时将禁用按钮。

于 2016-07-29T09:51:28.160 回答