AngularJS form validation directive for showing input errors

后端 未结 4 2092
我寻月下人不归
我寻月下人不归 2021-02-01 09:12

I need to create a validation directive for showing all input errors for each input automatically. This validation directive should show all errors at current moment and list of

4条回答
  •  情歌与酒
    2021-02-01 09:46

    all input errors for each input automatically

    Personally, I see more cons than pros from that phrase.

    1. Hiding error messages into javascript from html.

    • I think it's better to show as much info. as possible to developers with html in a understandable way,
      and I believe it is the way to go.

    2. Adding complexity for the future custom error messages.

    • What if your next developer wants to change error messages to, Hey, your input is too short.
      Do you want him to abandon your general error messages? Or, change it in your javascript?

    • What if your next developer add his custom error messages using ng-show.
      Then, you will have two error messages meaning the same.
      Then, will you not allow to have that? or, your general directive error message should be hidden? Or, apply that custom error message into general error message? If so, then how? See, it gets complex.

    IMHO, this general error message only works when you are very sure of the following;

    • Error messages are all the same on many many many pages.
    • Error messages will NEVER change in any case in the future.
    • html developers should not care about error messages.
    • No custom error message is allowed.

    If you are not sure about the above I mentioned, I would recommend not to create a general error messages.

提交回复
热议问题