0

<button type="submit" 
        class="btn btn-primary" 
        [disabled]="!complexForm.valid">
  Submit
</button>

My Submit button on the form is getting enabled when the form is not really valid. Old object == New object. Example user changes the value on a field, changes mind and enters same value again. The Submit button is now enabled and under the hood I could treat the Submit like a cancel and trick the user. However a better approach is to not show the Submit button at all until it is really valid. Where and how do I override Angular setting the form.valid property with my own logic where I check old new object and set form.valid myself

Aleksey Solovey
  • 4,153
  • 3
  • 15
  • 34
Gullu
  • 3,477
  • 7
  • 43
  • 70
  • Sounds like the easier thing to do is base the disabled property of the form on a diff of your original object and the `form.value` instead of trying to override the form. – Brandon Taylor Sep 21 '18 at 15:07
  • 1
    Seems like something is wrong with your validation if your form is "valid" when you say it's not really valid. Show us the rest of your validation code. – Mark Sep 21 '18 at 16:03
  • @Brandon, where do you put that logic ? { if (oldObj <> newObj> then form.valid = false; – Gullu Sep 21 '18 at 18:09
  • I found a way to do this as explained here https://stackoverflow.com/questions/37815194/angular2-interdependent-form-field-validation – Gullu Sep 21 '18 at 18:13
  • @Gullu it could be a function on the view model or it could also be the validator for the FormGroup as a whole, which is what you'd use for interdependent fields on the form, or you could make it a shared function, part of a base view model class... there are many options. – Brandon Taylor Sep 21 '18 at 23:55

0 Answers0