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

react-native-joi-form-decorator

v0.3.5

Published

A Joi validator for decorating your React Native forms

Downloads

3

Readme

Build Status npm version

React Native Joi Form Decorator

A decorator for your forms validated through Joi from Hapi.js. Build you form, decorate it with React Native Joi Form Decorator providing a valid Joi object prop.

Installation

npm install --save react-native-joi-form-decorator

How does it work?

Import component and validationsStates enum first

import { Validator, validationStates } from 'react-joi-form-decorator'

The Validator component takes 2 props, a data object and a joiObject which represents the Joi validation object.
The render method provides 2 outputs, an isValid flag and a validations data object, where each key of this object is a key from the provided data object, and the value is anobject with a state and error parameters.

state could be one of validationStates.CORRECT, validationStates.WRONG, validationStates.EMPTY

error is a string explaining why data is wrong (in English! Localization is not supported yet)

React Native configuration

You should install react-native-joi since it is used as an external dependency

npm install --save react-native-joi

Browser configuration

Please refer to react-joi-form-decorator

Basic Usage

Here's a simple example:

import React from 'react'
import { Validator, validationStates } from 'react-joi-form-decorator'
import Joi from 'joi'

class MyForm extends React.Component {
    constructor (props) {
        super (props)
            
        this.state = {
            data: {
                name: 'Frankie Frankson'
            }
        }
    }
    
    render() {
        const { data } = this.state
        
        return (
            <Validator data={data} joiObject={Joi.object().keys({name: Joi.string().min(5).required()})}>
                {(isValid, validations) => (
                    <div>
                        <label>Your name:</label>
                        <input type="text" name="name" value={data.name} onChange={() => {
                            // an update state function
                        }} />
                        {
                            validations.name.state === validationStates.WRONG && <label>{validations.name.error}</label>
                        }
                        <button type="submit" disabled={!isValid}>Submit</button>
                    </div>
                )}
            </Validator>
        )
    }
}

More power!

react-joi-form-decorator works great with react-attire!

Here's an other example:

import React from 'react'
import { Attire } from 'react-attire'
import { Validator, validationStates } from 'react-joi-form-decorator'

class MyForm extends React.Component {
    render() {
        return (
            <Attire initial={{name: 'Frankie Frankson'}}>
                {(data, onChange, reset) => (
                    <Validator data={data} joiObject={Joi.object().keys({name: Joi.string().min(5).required()})}>
                        {(isValid, validations) => (
                            <div>
                                <label>Your name:</label>
                                <input type="text" name="name" value={data.name} onChange={() => {
                                    // an update state function
                                }} />
                                {
                                    validations.name.state === validationStates.WRONG && <label>{validations.name.error}</label>
                                }
                                <button onClick={reset}>Reset my name!</button>
                                <button type="submit" disabled={!isValid}>Submit</button>
                            </div>
                        )}
                    </Validator>
                )}
            </Attire>
        )
    }
}

Contributing

If you see something you don't like or think that something is broken, please open an issue or better yet, make a PR!

License

MIT