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

ms-react-reactive-form

v1.1.2

Published

an implementation of the Reactive Form concept in React, supporting Javascript and Typescript

Downloads

31

Readme

Ms React Reactive Form

an implementation of the Reactive Form concept in React, supporting Javascript and Typescript with Full support for Functioal and Class Components

Features

  • Useing FormGroup, FormControl, Validators
  • Initialize Form with a little amount of coding
  • Having BaseValidator to return error type for each Input with its own Validity and Form Validity with Submission Status
  • Having SetValidators and RemoveValidators to change Input Roles in runtime
  • Compatiable with Javascript and Typescript
  • Compatiable with Functional and Class Components =

Full Example

Full Example in https://github.com/EgAlexDeveloper/Ms-React-Reactive-Form please check the Js and Ts branches

Teck

  • [React JS] - built for React Java script applications
  • [React TS] - built for React Type script applications
  • [Typescript] - the plugin build in Typrscript and transpilied to Javascript

Installation

Install the dependencies and devDependencies and start the server.

yarn add ms-react-reactive-form
npm i ms-react-reactive-form

Typescript Examples

Funtional Component

    // init FormGroup
    const form: FormGroup = new FormGroup({
        password: new FormControl("", [Validators.required(), Validators.pattern(/[0-9]/)])
    });
    
    // Store Form in State
    const [passwordForm, updatePasswordForm] = useState<FormGroup>(form);
    
    // Form Submit
    const save = (event: FormEvent<HTMLFormElement>) => {
        event.preventDefault();
        
        // Call Reactive Form Base Validator
        let validate = new BaseValidator(passwordForm);
        // Process validation
        validate.analysis()
            .then(controls => {
                // Fetch Final Validation Results
                let res = validate.result(controls);
                
                // update form state must be called here
    
                // handel success submittion
                if (res.form.validity) {
                    console.log(res.payload);
                } else {
                    // handel failed submittion
                    console.log(res.form)
                }
            });
    };
    
    // Update Form Values
    const changeHandler = (event: FormEvent<HTMLInputElement>) => {
        const { name, value } = event.currentTarget;
        passwordForm.controls[name].setValue(value);
        // update form state must be called here
    };

    // Reset Password Value
    resetPassword = () => {
        passwordForm.controls[Control Name].setValue("");
        // Update Form State Here
    };
    
    // remove Validators
    const removePasswordValidators = () => {
        passwordForm.controls[Control Name].removeValidators([List of Validators]);
        // update form state must be called here
    };
    
    // Set Validators
    const setPasswordValidators = () => {
        passwordForm.controls[Control Name].setValidators([List of Validators]);
        // update form state must be called here
    };
    
    return (
        <form onSubmit={save}>
            <div>
                <input
                    name="password"
                    id="password"
                    placeholder="password"
                    value={loginForm.controls.password.value}
                    onChange={(event: FormEvent<HTMLInputElement>) => changeHandler(event)}
                />

                {
                    passwordForm.controls.password.validity === false &&
                    <span>
                        {
                            passwordForm.controls.password.errors.required &&
                            <span>Password is Required</span>
                        }

                        {
                            passwordForm.controls.password.errors.pattern &&
                            <span>Password pattern error</span>
                        }
                    </span>
                }
            </div>
        </form>
    )

Class Component

    state = {
        passwordForm: new FormGroup({
            password: new FormControl("", [Validators.required(), Validators.pattern(/[0-9]/)])
        })
    };
    
    save = (event: FormEvent<HTMLFormElement>) => {
        event.preventDefault();
        const { passwordForm } = this.state;

        let validate = new BaseValidator(passwordForm);
        validate.analysis()
            .then(controls => {
                let res = validate.result(controls);
                // Update Form State Here

                if (res.form.validity) {
                    console.log(res.payload);
                } else {
                    console.log(res.form)
                }
            });
    };
    
    changeHandler = (event: FormEvent<HTMLInputElement>) => {
        const { passwordForm } = this.state;
        const { name, value } = event.currentTarget;
        loginForm.controls[name].setValue(value);

        // Update Form State Here
    };
    
    resetPassword = () => {
        const { passwordForm } = this.state;
        passwordForm.controls[Control Name].setValue("");
        // Update Form State Here
    };
    
    removePasswordValidators = () => {
        const { loginForm } = this.state;
        passwordForm.controls[Control Name].removeValidators([Validators.min, Validators.max, Validators.required()]);
        // Update Form State Here
    };

    setPasswordValidators = () => {
        const { loginForm } = this.state;
        passwordForm.controls[Control Name].setValidators([Validators.required()]);
        // Update Form State Here
    };
    
    render() {
        const { passwordForm: { controls } } = this.state;
        
        return (
            <form onSubmit={this.save}>
                <h1>Class Form</h1>
                <div>
                    <input
                        name="password"
                        id="password"
                        placeholder="password"
                        value={controls.password.value}
                        onChange={this.changeHandler}
                    />

                    {
                        controls.password.validity === false &&
                        <span>
                            {
                                controls.password.errors.required &&
                                <span>Password is Required</span>
                            }

                            {
                                controls.password.errors.pattern &&
                                <span>Password pattern error</span>
                            }
                        </span>
                    }
                </div>
            )
        }

| Name | Description | | ------------- | ----------- | | FormGroup | to create Form Group containing all Controls | | FormControl | to create Form Control containing all Input Methods and roles | | Validators | require, min, max, minLength, maxLength, pattern | | BaseValidators | analysis, result to return validations | | removeValidators | take list of not needed validators | | setValidators | take list of needed validators |

License

MIT