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

@chipp972/form-validation

v1.5.0

Published

Form component and wrapper to connect individual inputs

Downloads

29

Readme

form-validation

Description

Form components to manage validity of form fields.

Examples

import { Form, useForm, hasBetweenChecked } from '@chipp972/form-validation';
import { InputText, CheckboxGroup, Select } from '@chipp972/form';
import { PreviousButton, ValidationButton } from '@chipp972/buttons';

// Wrap the components to have access to validation data and methods
// (hasError, isValid, isInitial, updateFieldState and resetFieldState)
const MyInput = ({ name, validate, errorMessage, label, ...props }) => {
  const { hasError } = useForm({ name, validate, errorMessage });
  return (
    <>
      <label htmlFor={name}>
        {label}
        <input {...props} name={name} id={name} />
      </label>
      {hasError && <span>{errorMessage}</span>}
    </>
  );
};

export const MyForm = ({ formElementData, successCallback, failureCallback }) => (
  <Form onValidationSuccess={successCallback} onValidationFailure={failureCallback}>
    <MyInput
      label={formElementData[0].label}
      name={formElementData[0].name}
      validate={(value) => value === 'test'}
      errorMessage={formElementData[0].errorMessage}
    />
    <PreviousButton type="reset">Reset</PreviousButton>
    <ValidationButton type="submit">Validate</ValidationButton>
  </Form>
);

FAQ

Validate input directly

To validate the inputs when mounted just create a class component with a componentDidMount lifecycle method or add a useEffect hook and trigger updateFieldState from there.

Trigger validation/reset manually

To validate the form manually get a ref of the Form component and trigger formRef.current.submit() or formRef.current.reset(). You can also use a querySelector if you put an id on the form for example: document.querySelector('#formId')?.requestSubmit().

Changelog

1.5.0

  • Expose FieldState enum
  • forwardRef of the Form component to trigger submit and reset manually

1.4.3

  • Use ramda es5 imports

1.4.2

  • Fix do not put the values of unchecked checkboxes in the result

1.4.1

  • Fix @emotion/core injected in build files

1.4.0

  • Expose filterUseFormProps to avoid React warnings for invalid props
  • Add dependentFields prop to pass an array of field names that should trigger validation when the field changes

1.3.0

  • Add validateDependencies to reconnect the field if the validate function has to be updated