4

I have a large form part, that shall be disabled in some scenarios. I am using a <fieldset> tag with ng-disabled attribute, to enable/disable the form part.

 <ng-form name="myForm">
    <fieldset ng-disabled="myModel.isFieldsetDisabled">
      <input id="myTextField" type="text" ng-required="true" ng-model="myModel.myAttribute">
      ... lots of other fields
    </fieldset>
  </ng-form>

The problem is: When I disable the <fieldset>, the ng-form is still invalid, because some of the input fields are empty (but ought to be required). I expected these validations to be turned off when disabled.

How to achieve a valid ng-form without fumbling with all ng-required attributes on all input fields in the disabled form.

see the plunker: https://plnkr.co/edit/2JpSFqBqwdfgTa2wO4Ei?p=preview

girafi
  • 131
  • 7
  • So you'd like the input ng-required attribute to be set to false when the fieldset is disabled right? – fbid Apr 11 '16 at 12:47
  • Only way I can think of is setting the ng-required attribute to use the reversed flag of your ng-disabled like so `ng-required="!myModel.isFieldsetDisabled"` – KieranDotCo Apr 11 '16 at 12:51
  • I would expect that angular skips validation for disabled fields..? – devqon Apr 11 '16 at 13:39
  • @fbid I have a quite a lot of input and select fields within the disabled fieldset. So a solution that needs adaptation to every field would not be the first choice. – girafi Apr 12 '16 at 13:59
  • @KieranDotCo see comment above – girafi Apr 12 '16 at 13:59
  • @devqon Me too :) but the reality is not with us :( – girafi Apr 12 '16 at 14:00

1 Answers1

3

I would try with something like this:

ng-required="!myModel.isFieldsetDisabled"

i.e.: input is required if myModel.isFieldsetDisabled variable is false...

MarcoS
  • 17,323
  • 24
  • 96
  • 174
  • The point is, that i have a full sreen page of input and select widgets inside the ´
    ´. (see '... lots of other fields' in the question).If anyone finds a solution without touching each and every input field
    – girafi Apr 12 '16 at 14:02
  • I think a solution without adding a ng-required attribute to every input field does not exist, sorry... – MarcoS Sep 07 '16 at 15:29