npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mark-invalid-form-controls

v1.0.6

Published

Mark all invalid reactive form controls and scroll to first invalid control

Downloads

14

Readme

Angular Mark Invalid Form Controls Utility

The markInvalidFormControls function is a utility function for Angular applications to be used with Reactive Forms that helps you mark all invalid form controls as dirty and scrolls smoothly to the first invalid control. This utility is useful for providing better user experience in forms with validation, making it easier for users to identify and correct the invalid inputs.

Why use this utility?

When working with Angular forms, you might have scenarios where a user submits a form without filling in all required fields or providing invalid data. In such cases, it is essential to inform the user about these errors and guide them to correct the inputs. The markInvalidFormControls utility function helps you achieve this by marking all invalid controls as dirty and scrolling to the first invalid control on the form.

When to use it?

You should use this utility function when you have a form with validation, and you want to provide a better user experience by guiding the user to the first invalid input when the form is submitted with invalid data.

How to use it?

  1. Install the package using npm:

    npm install mark-invalid-form-controls

  2. Import the markInvalidFormControls function in your component:

    import { markInvalidFormControls } from 'mark-invalid-form-controls';
  3. Use the markInvalidFormControls function in your component, typically in the submit event handler:

    onSubmit() {
        if (this.myForm.invalid) {
            markInvalidFormControls(this.myForm, this.el);
        } else {
            // Handle successful form submission
        }
    }
  4. Pass the ElementRef instance of the component as the second parameter to the function. You can get the ElementRef by injecting it into your component's constructor:

    constructor(private el: ElementRef) {}

    Then pass this.el as the second parameter when calling the markInvalidFormControls function:

    markInvalidFormControls(this.myForm, this.el);

Dependencies

To use this utility function, you must have the following dependencies installed in your Angular project:

@angular/core: This is a core dependency of any Angular application.
@angular/forms: This is required to work with Angular forms.

The utility function relies on the AbstractControl, FormArray, FormControl, and FormGroup classes from the @angular/forms package, and the ElementRef class from the @angular/core package.

Function signature

  • control: An AbstractControl instance representing the form control, form group, or form array you want to mark as dirty.

  • elRef: An ElementRef instance representing the component where the form resides. This parameter is required for scrolling to the first invalid control.

License

This project is licensed under the MIT License. For more information, please see the LICENSE file.

Author

Contributing

Contributions are welcome! If you find a bug or would like to request a new feature, please feel free to open an issue or submit a pull request on the project's GitHub repository.

To contribute:

  1. Fork the repository on GitHub.
  2. Clone your fork and create a new branch for your feature or bugfix.
  3. Commit your changes, and push the branch to your fork.
  4. Create a pull request from your fork to the original repository.

Please make sure to follow the project's coding style and include tests and documentation for any new features or bugfixes.