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

@cisco-msx/forms

v6.0.7-alpha

Published

MSX form builder, renderer, and field components

Downloads

10

Readme

@cisco-msx/forms

Form builder classes, renderer, and Angular upgrades for MSX form field components.

Usage

import { NgModule } from '@angular/core';
import { MsxFormsModule } from '@cisco-msx/forms';

@NgModule({
  imports: [
    MsxFormsModule
  ]
})
export class MyModule {}

Testing

If you are testing your component using Angular's TestBed, import the MsxFormsTestingModule in your testing module instead of MsxFormsModule to have @cisco-msx/forms's components and directives mocked.

import {
  async,
  ComponentFixture,
  TestBed
} from '@angular/core/testing';
import { MsxFormsTestingModule } from '@cisco-msx/forms/testing';
import { MyComponent } from './my.component';

describe('MyComponent', () => {
  let component: MyComponent;
  let fixture: ComponentFixture<MyComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        MsxFormsTestingModule
      ],
      declarations: [MyComponent]
    });
    fixture = TestBed.createComponent(MyComponent);
    component = fixture.componentInstance;
  }));
});

Form Fields

The upgraded form inputs that can be used are also included in the MsxFormModule. You can find the upgraded components here.

Form Builder/Renderer

This package contains the Form and FormGroup classes that are the basis for being a structure for your form. It also contains the DynamicFormComponent that takes instances of the Form and FormGroup to automatically render and handle the change lifecycle of the fields within them.

Note: If fields are added to a Form and a FormGroup you must render 2 dynamic form components as fields are encapsulated into the instance of where they are added even if all values are available in the top level form

The following is an example of how to use the dynamic forms using a Form and a FormGroup. This example uses Angular 8 but you can build forms (without the dynamic rendering) with any (or no) framework.


@Component({
    selector: 'my-component',
    template: `
    <div>
        <div>
            <h1>Name Information</h1>
            <msx-form [form]="nameForm"></msx-form>
        </div>
        <div>
            <h1>Location Information</h1>
            <!--Without passing the locationFormGroup, the address and postal code fields would never show  -->
            <msx-form [form]="locationFormGroup"></msx-form>
        </div>
    </div>
`
})
class MyComponent {

    nameForm = new Form();
    locationFormGroup = new FormGroup('locationGroup');

    ngOnInit() {
        this.nameForm.setFields([
            {
                name: "firstName",
                initialValue: "",
                properties: {
                    label: "First Name",
                    required: true,
                    placeholder: "Johny"
                }
            },
            {
                name: "lastName",
                initialValue: "",
                properties: {
                    label: "Last Name",
                    required: true,
                    placeholder: "Bravo"
                }
            }
        ]);

        this.locationGroup.setFields([
            {
                name: "address",
                initialValue: "",
                properties: {
                    required: true,
                    label: "Address",
                    placeholder: "123 Somewhere Lane"
                }
            },
            {
                name: "postalCode",
                initialValue: "",
                properties: {
                    label: "Postal Code",
                    required: true,
                    placeholder: "K0F K8A"
                }
            }
        ]);


        this.nameForm.setFormGroup(this.locationGroup);
    }
}

The example above would render a section header Name Information with 2 fields (firstName, lastName) and another section header Location Information with the 2 fields (address and postal code). Note that 2 msx-form components where used, one for the Form and one for the FormGroup. This is because fields are encapsulated where they are added. However, the Form will still know when a field from a child FormGroup changes.

Other Resources