Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Trigger ngMessage validation onblur or with timeout #7416

Closed

Description

@kkozmic

I just read the blotpost at yearofmoo about ngMessages. I think the module is a welcome addition but I find that the first available beta has certain gaps. //cc @matsko

  1. Primarily, the validation jumps the gun kicking in as soon as I start editing the field. Say for email, obviuosly email is not going to be valid for the first several characters I type.
    The way I used to solve it, is hooking into onblur, so that the user only sees the error once they move to the next field.
  2. For things like checking username/passwords through a remote API call I always use $timeout so that I don't hammer the API as the user is typing, and I don't distract them with useless messages as they are doing so. Again, some built in support in the module would be highly desirable.
  3. Clicking the submit button should call the submit() function only if the validation passes. Otherwise it should only trigger (re)validation of the form.

I'm happy to discuss this further is there are any questions, or to split that into three separate issues if that's preferred.

Activity

  1. matsko commented on May 10, 2014

    @matsko
    Contributor

    Hey @kkozmic.

    The forms in Angular are being reworked a bit, but ngMessage is solely there for displaying messages. The core is being fixed to allow for more flexibility with when the errors are updated.

    1. Debouncing can be used if you want the errors to only update once the input field is blurred (look at ngModelOptions).

    2. This may work with debouncing as well. And once the new validators system (ngModelController.$validators pipeline and refactoring #7377) is in then it should be much easier.

    3. AngularDart has a $submitted property which will be brought into AngularJS soon. For now, with ngMessages, it's best to use your own submitted variable, but once this is in then you won't need to, but you'll still need an ngIF. I think the long term goal is to have debouncing determine exactly when the errors are updated upon submit. There will also be a $touched property (which is called when the input field is blurred or when the form is submitted).

    Also #7377 introduces a better validation system which can you can call explicitly.

  2. IgorMinar commented on May 22, 2014

    @IgorMinar
    Contributor

    1/ and 2/ are addressed in 1.3.-beta builds with ngModelOptions.

    3/ depends a lot on the validation style you want to use in your app. #7377 might help here, but even without it, in the submit callback you can check if the whole form is valid. If it is, move on. If it's not, display validation messages and abort submit. In most apps we want to provide the validation feedback sooner than on form submit, so this should not be the default behavior.

  3. IgorMinar commented on May 22, 2014

    @IgorMinar
    Contributor

    There is also #7016 which is somewhat related.

  4. btford commented on Jul 23, 2014

    @btford
    Contributor

    I think these issues have been largely addressed in 1.3. I am going to close this, but if there's still some case that ngMessage doesn't handle well, feel free to file another issue @kkozmic.

  5. kkozmic commented on Jul 23, 2014

    @kkozmic
    Author

    no worries.

    I'll let you know after we upgrader to 1.3.

    ta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions