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

@ezderm/ez-form

v1.26.0

Published

useForm - custom react hook for handling complex forms

Downloads

139

Readme

Basics

  • Keep input value and error in state
  • Handle onChange event on input to update state (validation is performed here)
  • "externalized" formElement (formElements file)
  • defaultValue * label, label2

Additional requirements

  • Trigger an action on input change (get some data, update another field, …)
  • Validate another field (validateAnotherField) on input change (i.e. password confirmation - when password is changed, confirmation should be validated again)
  • withDependancy validation
  • Update another field(s) on change (i.e country-state selects or clinics-primary clinic, address same as patient's)
  • multiselect onValueClick
  • isVisible (invisible items don't pass through validation nor are included in prepareForServer result) (probably will be a part of schema)
  • disabled field
  • pass additionalProps specific to underling element (i.e. options for select, optionRenderer, labelIcon, etc.) * dynamic sub-foms - be able to dynamically extend schema (i.e add contact method (1 field), add address info(group of fields))

Form utils

  • init form from schema with initial data
  • prepare form data for server (withAdditionalProps option for selects)
  • clone form data to be able to revert form to some previous state
  • update form state - setSchemaStateValue, setSchemaStateValues (Bulk) * validate function

Differences with original schema:

  • withDependancy validation: no wraper function withDependancy, instead we skip validator function if args have dependencyField and dependency value is different than in state or the state value is falsy

  • if we pass dependencyInValidationArgs: true in val rule args, than compare dependencyValue with value passed as arg in validate function

    Tests

    • init.test

      • init default value from schema (keep value in state)
      • default isVisible flag in schema
      • init values with second arg
      • label and label2
      • select init with obj/string that is/is't in options
      • multi select ([] with obj/string that is/is't in options)
    • update.test

      • update field value in state onChange
    • validation.test

      • validate value on inputChage
      • support string and intl error messages (message is handled in formElemet)
      • support default and custom error messages
      • args property for validation func (based on another schema field or fixed arg)
      • validate another field
      • prevent cyclically validation with validate another field (validate another field only on field change)
      • with dependancy validation
    • render.test

      • render componet based on isVisible prop in arg
      • disable component based on disabled prop in arg
      • onChange cb for text input and selet
      • onInputChange for select
    • prepareForServer.test

    • setSchemaStateValue.test

    • getSchemaStateValue.test

    • cloneStateValues.test

    • npm publish --access public

Publish

  1. commit all work with clean Flow and Eslint warning output
  2. make sure that all tests are passing
  3. increment version in package.json
  4. run "npm publish --access public"

Flow:

  • check type of variable in file: flow type-at-pos /path/to/file.js 6 6

API

Table of Contents

useForm

useForm

Parameters

getSchemaStateValue

getSchemaStateValue

Parameters

Returns SchemaValue

setSchemaStateValue

setSchemaStateValue

Parameters

  • $0 SetSchemaStateArgs

    • $0.fullFieldName
    • $0.newValue
    • $0.skipValidation (optional, default false)
    • $0.onComplete

Returns void

setSchemaStateValueBulk

setSchemaStateValueBulk

Parameters

validate

validate

Parameters

  • dependencyArgs {}? some additional arguments thet we want to pass to validation function

Returns boolean

prepareForServer

prepareForServer - function that returns object with pairs fieldName: value

Returns ValuesMap

cloneStateValues

cloneStateValues - very similar to prepareForServer. The only difference is that it doesn't transform values at all, i.e. select/multiselect, trimming, etc

Returns {}

addDynamicItem

addDynamicItem

Parameters

removeDynamicItem

removeDynamicItem

Parameters

RenderFieldFunctionArgs

RenderFieldFunctionArgs

Properties

ComponentType

Component from React

IntlMessageDescriptor

IntlMessageDescriptor

Properties

IntlMessage

IntlMessage

Properties

InputType

InputType

Type: ("TEXT_INPUT" | "MASKED_TEXT_INPUT" | "SELECT_INPUT" | "MULTISELECT" | "CHECKBOX" | "RADIOGROUP" | "TEXT_AREA")

FormElement

FormElement

Properties

Label

Label

Type: (string | IntlMessage)

ErrorMessage

ErrorMessage

Type: (string | IntlMessage)

ValidationRule

ValidationRule

Properties

SelectValue

SelectValue

Type: (string | {value: (string | number), label: string} | null)

MultiSelectValue

MultiSelectValue

Type: (Array<string> | Array<{value: (string | number), label: string}>)

SchemaValue

SchemaValue

Type: (string | number | boolean | Array<string> | SelectValue | void | {})

MaskedInputEventTarget

MaskedInputEventTarget

Properties

MaskedInputSynteticEvent

MaskedInputSynteticEvent

Properties

StandardFieldMetadata

StandardFieldMetadata

Properties

DynamicFieldMetadata

DynamicFieldMetadata

Properties

  • dynamicSchemaItem {}

FieldMetadata

FieldMetadata

Type: (StandardFieldMetadata | DynamicFieldMetadata)

Schema

Schema - object that serves as a map of field names and its data

SetSchemaStateArgs

SetSchemaStateArgs

Properties

ValuesMap

ValuesMap - object that maps each fieldName with its (new) value

SetSchemaStateValueBulkArgs

SetSchemaStateValueBulkArgs

Properties

StandardFieldState

StandardFieldState

Properties

DynamicFieldState

DynamicFieldState

Properties

  • isDynamic true
  • value Array<{}>

FieldState

FieldState

Type: (StandardFieldState | DynamicFieldState)

FormState

FormState

InitValuesMap

InitValuesMap

AddDynamicItemArgs

AddDynamicItemArgs

Properties

RemoveDynamicItemArgs

RemoveDynamicItemArgs

Properties