A simple approach to displaying form validation messages in Angular

Поділитися
Вставка
  • Опубліковано 16 вер 2024

КОМЕНТАРІ • 37

  • @JoshuaMorony
    @JoshuaMorony  Рік тому

    Join my mailing list for more exclusive content and access to the archive of my private tips of the week: mobirony.ck.page/4a331b9076

  • @baluditor
    @baluditor 2 роки тому +11

    I love the fact that you expleind in detail what that #form="ngFrom" means. Thanks for that.

    • @additionaddict5524
      @additionaddict5524 2 роки тому

      I use forms all the time and had no idea!

    • @bromptonhorsing8597
      @bromptonhorsing8597 Рік тому

      I also appreciated that. It's difficult to find more technical yet simple explanation, would like to see more 🤔👀

  • @CraigShearer
    @CraigShearer 2 роки тому +2

    Thanks Josh - the deep dive into FormGroupDirective (at 4:40) is really interesting and intriguing to see how it works under the hood. Seeing how events are wired up in host blew my mind :)

  • @magmarrex5939
    @magmarrex5939 2 роки тому

    This channel is pure gold. I love how you touch the backside details.

    • @kaibe5241
      @kaibe5241 Рік тому

      Everyone loves a good backside touch.

  • @Rollout123
    @Rollout123 Рік тому

    Great Video...simple, concise, thorough. Perfect for explaining submit, validation, etc.

  • @AlainBoudard
    @AlainBoudard 2 роки тому

    Clean and simple approach, well done Josh !

  • @ranjanadeore2957
    @ranjanadeore2957 2 роки тому +1

    Thank you sir for uploading great tutorials

  • @solartcom
    @solartcom 2 роки тому

    It's always a good day when I see a new upload from you !

  • @OLIV3R_YT
    @OLIV3R_YT 2 роки тому

    Thanks for explaining ngForm

  • @mariosfrixou7003
    @mariosfrixou7003 Рік тому

    I always use formly in my angular projects. Never bothered with angular’s FormBuilder and never had to be honest!

  • @Billy_Herrington__
    @Billy_Herrington__ 2 роки тому +4

    This looks to me so over complicated tbh. Why do you need #form, when you can just use form.markAllAsTouched() in submit method, and in template you will do like this ngif = control.touched && control.errors.required (or what ever your error is named)

  • @jeremiasaragonbonilla2167
    @jeremiasaragonbonilla2167 2 роки тому

    Amazing! Thanks Josh

  • @petraveryanov2572
    @petraveryanov2572 2 роки тому +1

    Isnt it kinda standard approach? Except that strange 'onBlur' thing e.g.. if I entered invalid e-mail, then clicked submit, then entered valid e-mail I will still see validation error which is weird.

  • @edavar6265
    @edavar6265 2 роки тому

    Great video as always. Thanks!

  • @ankit0120
    @ankit0120 2 роки тому +3

    already used it in a few places but the issue is I have [disabled] bind with form.invalid and it does not update until I click out of the field. so users will never get to know if the value is right or not. did you face similar issue ?

    • @JoshuaMorony
      @JoshuaMorony  2 роки тому +1

      I don't disable form submit if the form is invalid - the user can still click the submit button and it will trigger showing the errors but won't actually submit the form. I don't know the in-depth UX reasoning behind this, but as far as I am aware this approach is preferable to disabling the submit button.

    • @andreafresu5009
      @andreafresu5009 2 роки тому

      @@JoshuaMorony avoid button disabling is the best approach because of accessibility reasons.
      Great videos, just subscribed 👍!

  • @rhatalos1997
    @rhatalos1997 2 роки тому +2

    I think a good idea would be to create an error component, which displays default messages for the existing validators.

  • @daniellynch3724
    @daniellynch3724 Рік тому

    How did you place the custom validator in like that? I always have to do a long call including a this bind, and have to inject the validator in the component constructor

  • @dinesh.m7341
    @dinesh.m7341 Рік тому

    Thanks bro

  • @loko1944
    @loko1944 Рік тому

    In this case we could also createForm.dirty in template instead of form.dirty, right? its still reference this same form

  • @kandeepasundaram2501
    @kandeepasundaram2501 Рік тому

    Is there a way to clear the form validation errors on focus of any fields?

  • @scuroguardiano9787
    @scuroguardiano9787 Рік тому

    Can't we just mark form as dirty on submit? One line in component logic and much simpler conditions in template.

  • @rajatnegi3896
    @rajatnegi3896 2 роки тому

    How is the template html color coded in the ts file ? Or is it a ionic specific thing. Sorry i haven't used ionic yet.

    • @JoshuaMorony
      @JoshuaMorony  2 роки тому

      The Angular Language Service extension handles syntax highlighting for inline templates

  • @ReadyVred
    @ReadyVred 2 роки тому

    this is great, but how can you display a multiple error messages ? or maybe if the input have 2 condition like required and maxlength, so the message must be different on each validation.. how can we achieve that ? btw thanks for the tutorial

    • @JoshuaMorony
      @JoshuaMorony  2 роки тому +1

      If you want something more complex (e.g. showing specific error messages for multiple validations) then I wouldn't recommend the approach in the video. You could add some more logic onto it to grab the specific validator that failed and write a custom message for it, but at that point I think you would be better served either by: creating your own custom component/directive that takes in the form control and displays an error message, or better yet just use one of the existing libraries for dealing with forms since people have already solved this problem.

  • @thanhcongpham5422
    @thanhcongpham5422 2 роки тому

    👍👍

  • @nimitdesai93
    @nimitdesai93 2 роки тому

    why is my gms softing like static?

  • @szymonlisiecki2789
    @szymonlisiecki2789 2 роки тому

    nice video but imo music is too loud

  • @mahmoudtarek745
    @mahmoudtarek745 Рік тому

    Thanks for Your video. But to be honest i think this is too much for handling validation not a simple approach why you do not just use markAllAsTouched()

  • @jorgerenteral
    @jorgerenteral 2 роки тому +1

    What do you think about the "createForm.controls.email.touched && createForm.controls.email.errors" syntax?