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

pronto-validated-form

v0.1.16

Published

Helpers for creating a form with validated fields.

Downloads

4

Readme

validated-form

Helpers for creating a form with validated fields.

ValidatedForm

Properties

  • fields An object of field names and options {name: options, ...}. See field options for more information
  • values An object of field values {name: value, ...}
  • onSubmit(values) A function to be called when the form is submitted (only if fields are valid)

Example

<ValidatedForm ref='form' fields={
    city: {}
    state: {placeholder: 'e.g. "NY" or "MA"'}
    county: {optional: true}
} onSubmit={({city, state, county}) -> alert(city + ' is in ' + state) } />

ValidatedField

Properties

  • name Name of this field
  • type One of "text", "number", "email", or "toggle", default is "text"
  • placeholder A placeholder, default is the un-slugified field name
  • error_message Message to show if field is invalid
  • hidden A boolean or function to determine if this field is hidden
  • optional A boolean or function to determine if this field is optional

ValidatedFormMixin

The ValidatedFormMixin provides methods for rendering fields, keeping track of fields state, and checking that fields are valid.

Class attributes

  • getInitialState() -> {values} required
    • A component that uses this mixin must define a getInitialState that returns at least an empty values: {}, because a React component does not have state by default
    • You can also use this to pre-fill values of fields, with e.g. values: {email: '[email protected]'}
  • getDefaultProps() -> {fields, onSubmit}
    • Define fields and other props here, or pass them in as props instead
  • onSubmit(values)
    • A function to be called when the form is submitted (only if fields are valid)
    • Can be defined directly on your class instead of as a property

Properties

  • fields An object of field names and options in the shape {name: options, ...}. See field options for more information
  • onSubmit(values) A function to be called when the form is submitted (only if fields are valid)

State

  • values An object of values by field name

Methods from mixin

  • renderField(name) Render an individual field with the options in fields[name]
  • trySubmit() A method that looks through fields
  • clear() Sets all field values to null

Example

{ValidatedFormMixin} = require 'validated-form'

FormTest = React.createClass
    mixins: [ValidatedFormMixin]

    getInitialState: ->
        values:
            name: 'test'

    getDefaultProps: ->
        fields:
            name: {type: 'text'}
            age: {type: 'number'}
            email: {type: 'email'}

    onSubmit: (values) ->
        @setState {loading: true}
        submitFormAnd =>
            @clear()
            @setState {loading: false}

    render: ->
        <div>
            <form onSubmit=@trySubmit>
                {@renderField 'name'}
                {@renderField 'age'}
                {@renderField 'email'}
                <button>{if @state.loading then "Loading..." else "Submit"}</button>
            </form>
        </div>