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

@o3r/forms

v11.5.4

Published

This module provides utilities to enhance angular form (asynchronous decorator, additional validator, error store...).

Downloads

28,380

Readme

This package is an Otter Framework Module.

Description

Stable Version Bundle Size

This module provides utilities to enhance Angular form (asynchronous decorator, additional validator, error store...).

How to install

ng add @o3r/forms

[!WARNING] This module requires @o3r/core to be installed.

Container/presenter and form creation

A Container/presenter architecture was put in place to ensure best reusability/sharing

Where the form object creation should be done?

  • form created in presenter - it's the presenter that decides how the data is displayed
  • container only values and errors are propagated from the presenter
  • container can set the default value

How the container and presenter will communicate in forms context

  • presenter implements ControlValueAccessor and Validator (or AsyncValidator) interfaces
    • propagate the value, the form status and the errors
  • container applies FormControlDirective on the presenter html tag
    • container sets the default value using formControl directive
    • listen to the value and status changes using the same directive

See FORM_STRUCTURE

You want to include form validation and display the errors

  • interfaces for the error messages provided in @o3r/forms

Display inline errors

  • the error messages returned by validators are used in the inline error display
  • simple/basic/primitive validators - set as a configuration of the presenter
    • localization of the associated error messages from the presenter
    • the error object associated is computed here and has to be compliant with the store object model
    • getFlatControlErrors function is available in @o3r/forms to help with the creation of the associated error object
  • custom validators created at container level
    • localization of the associated error messages from the container
    • custom validators are passed as an input to the presenter
    • the error returned by the validator has to be compliant with the form error store model

Display errors on a messages panel

  • a dedicated FormErrorStore is available on @o3r/forms
    • allows the display of errors anywhere on the page
    • the error object model contains the translation key and params See FORM_VALIDATION and FORM_ERRORS

Form submit

You want to submit the form

  • The submit is triggered by the submit button in the presenter and an event is emitted
  • container captures the event and executes the submit form logic

What happens when you have multiple forms and you want to submit?

The answer is that we should avoid as much as possible having multiple form tags in the same page as it adds a lot of complexity. We should try to have only one form tag that encapsulates everything and one submit action.

If multiple forms are really needed, then we found the following solution:

  • the submit button is hidden on the presenters
  • the submit is triggered from the page
  • an observable to trigger the submit is passed as input to the containers;
  • AsyncInput decorator is provided in @o3r/forms to be applied on the observable input to ensure performance
  • the submit form logic is executed on the containers
  • containers emit events when the submit is done
  • the page (parent) captures the events and continues its logic

This can be applied also, with only one form on the page, when you don't want a submit button in the presenter.

What happens when the submit is triggered by the page with pristine forms

At the first display of the form, the inline errors (if the form is invalid) are not displayed because the form element is not touched and dirty In case you want to show the inline errors after the submit, you have to:

  • register a function in the container to mark touched and dirty the form
  • pass the function via an @Output from the presenter and call it before executing the submit logic
  • use markAllControlsDirtyAndTouched helper is available in @o3r/forms to mark interactions on given form

See FORM_SUBMIT&INTERCOMMUNICATION

Details

Find more information in the documentation.