New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

valya-forms

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

valya-forms

Wrapper for valya to make forms easier

  • 0.2.0-alpha.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

Valya Forms

Valya Forms are just a tiny Higher-Order Components for Valya.

It provides props isValid and isValidating for wrapped component according to states of validators. Also it allows set initialValidation in form for all validators of this form.

Example

First we need to create valya validator and return it in wrapper:

import { Component } from 'react';
import { ValidatorWrapper } from 'valya-forms';
import Valya from 'valya';

class Validator extends Component {
    renderError() {
        const { enabled, isValid } = this.props;

        if (!enabled || isValid) {
            return null;
        }

        return <div className="error">{this.props.validationErrorMessage}</div>;
    }

    render() {
        return (
            <div className="validator">
                <div className="target">{this.props.children}</div>
                {this.renderError()}
            </div>
        );
    }
}

// This is only change
// We export not Valya(Validator) but ValidatorWrapper(Valya(Validator))
export default ValidatorWrapper(Valya(Validator));

Then we create form and wrap it too:

import { Component } from 'react';
import { FormWrapper } from 'valya-forms';
import Validator from './validator';

// simple react form component
class MyForm extends Component {
    constructor(props, context) {
        super(props, context);

        this.state = {
            email: props.email
        };

        this._onEmailChange = this._onEmailChange.bind(this);
    }

    _onEmailChange = (e) => {
        this.setState({
            email: e.target.value
        });
    };

    render() {
        // injected props by wrapper
        let { isValid, isValidating } = this.props;

        return (
            {/* prop initialValidation will be passed to all validators */}
            <form initialValidation={true}>
                {/* name & value props are required
                    they will be passed to valya and underlying component */}
                <Validator name="email" value={this.state.email} validators={validators}>
                    <input onBlur={this._onEmailChange} />
                </Validator>
                <div>{isValidating ? 'processing validation' : 'validation finished'}</div>
                <div>Form is {isValid ? 'valid' : 'invalid'}</div>
            </form>
        );
    }
}

// export form in wrapper
export default FormWrapper(MyForm);

Keywords

FAQs

Package last updated on 29 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc