0

I have a template driven form with two date inputs. The second one needs to be after the first one. I found some examples for creating custom validators but these approaches seem to be very complex and I don't think that something is necessary for this little problem and also this approach does not allow to validate two inputs interdependently.

<form #contractForm="ngForm">
    <md-input-container>
        <input type="date" mdInput name="validFrom">
    </md-input-container>
    <md-input-container>
        <input type="date" mdInput name="validUntil">
    </md-input-container>
</form>

I just thought about something like this

<input type="date" mdInput name="validUntil" [valid]="validFrom.value < validUntil.value">

You know a simple way to check this?

alex
  • 1,999
  • 3
  • 16
  • 18
  • I found a very hacky workaround with using the pattern attribute. I could check the input values onChance and set the pattern attribute for setting the input either valid or invalid. - I would not like this xD – alex May 05 '17 at 09:52
  • you can refer something like this http://stackoverflow.com/questions/43779438/angular-2-form-validations-start-date-end-date/43782594?noredirect=1#comment74607619_43782594 – sainu May 05 '17 at 10:55
  • this seems not to change validity of the form but only shows up an error. I have my submit button bound to the validity. – alex May 12 '17 at 07:01

0 Answers0