Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn Off Validation for Disabled Form Controls Angular

I have a button that is set to be disabled until the form is valid. However, depending on the situation some of the form fields are also disabled. My problem is, I need the user to only be required to fill in non-disabled form fields but angular doesn't seem to be validating the disabled fields.

<button ng-click="form.checkVerify(); appCtrl.pageLoad('spec')" ng-disabled="checkVerifyForm.$invalid" class="btn btn-lg btn-success pull-right">Complete</button>

<form name="checkVerifyForm">
  <div class="col-md-6">
    <fieldset ng-disabled="!form.dataStore.reqMake">
<label for="makeRec">Maker Recourse</label>
      <div class="form-group">
        <label class="radio-inline">
          <input ng-change="form.justify()" ng-model="form.verify.mRec" type="radio" name="makeRec" id="makeRecYes" value="1" /> Yes
        </label>
        <label class="radio-inline">
          <input ng-change="form.justify()" ng-model="form.verify.mRec" type="radio" name="makeRec" id="makeRecNo" value="0" /> No
        </label>
        <span id="helpBlock" class="help-block">Is there adequete recourse...</span>
      </div>

Now I have seen some pretty intense directives that accomplish the task, but is there something simple that can be done in the controller to overcome this specific situation?

like image 870
ThatTechGuy Avatar asked Oct 20 '22 18:10

ThatTechGuy


1 Answers

You can use e.g. ng-required to achieve that.

<input ng-change="form.justify()" 
       ng-model="form.verify.mRec" 
       type="radio" 
       name="makeRec" 
       id="makeRecYes" 
       value="1" 
       ng-required="form.dataStore.reqMake" /> Yes

AngularJS input documentation

like image 112
Henri Hietala Avatar answered Oct 22 '22 09:10

Henri Hietala