Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

valour-form

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

valour-form

ValourForm === #### The form validation component for use with [Valour](https://github.com/stevematney/valour) and [ES-Components](https://github.com/TWExchangeSolutions/es-components) ___

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

ValourForm

The form validation component for use with Valour and ES-Components

Props

NameTypeDefaultDescription
formNamestringRequiredThe name of the form
rulesobjectRequiredAll of the valour rules the form will use to validate
childrennodeRequiredThe child elements in the form
handleFormSubmissionfuncFunctionThe function to execute during a valid submit
preventDefaultSubmissionBehaviorboolfalseCall preventDefault() on submit
setValidationTypeForFormenumYou can set the validation type for all fields in the form
One of: onChange, onBlur

Usage:


import { ValourForm } from 'valour-form';
//Create an object with your desired Valour rules
const rules = {
    Email: valour.rule.isRequired().isEmail()
}

<ValourForm rules={rules} formName="exampleForm" handleFormSubmission={this.doThisOnValidSubmit} >
    //The input name needs to match the rule key in order to validate it
    <ValourTextbox labelText="Email:" name="Email" />
    <Button>Submit</Button>
</ValourForm>

Note: It's not required to have a rule for every input. Inputs without rules will just not validate.

Setting Validation Types:

You can set the validation type of all Valoured inputs at once by using the setValidationTypeForForm property at the form level and choosing either onBlur or onChange.
By not using the setValidationTypeForForm property, validation will only occur on submit by default unless you put the validateOnBlur and/or validateOnChange properties on the individual inputs.

<ValourForm rules={rules} 
    formName="exampleForm" 
    handleFormSubmission={this.doThisOnValidSubmit} 
    setValidationTypeForForm="onChange"
>
    <ValourTextbox labelText="Textbox" name="Text" />
    <ValourTextbox labelText="Textbox Two" name="TextboxTwo" />

If you use the setValidationTypeForForm form-level property and add a validateOnBlur or validateOnChange property to an input, it will cancel out the form-level validation for that input.

    //This textbox will validate onblur instead of onchange like the other inputs
    <ValourTextbox validateOnBlur labelText="Another Box" name="LastBox" />
    <Button>Submit</Button>
</ValourForm>

Components Used With ValourForm:

ValourTextbox

Props

NameTypeDefaultDescription
namestringRequiredUsed to match the validation rule to the input
labelTextstringRequiredThe label text for the input
validateOnBlurboolfalseValidates after the text box loses focus
validateOnChangeboolfalseValidates after the text box value changes
successValidationboolfalseUses the green success coloring when input is valid

Note: Form will always validate all inputs on submit.

Usage:


import { ValourTextbox } from 'valour-form';
<ValourTextbox labelText="Textbox" name="Text"/>

//highlights the text box and label text with the green success coloring when it's rule requirements are met
<ValourTextbox successValidation labelText="Success Coloring Box" name="GreenBox"/>

ValourTextbox can still use the handleOnChange, handleFocusLost, and any other props on es-components's Textbox.

<ValourTextbox validateOnChange handleFocusLost={this.handleBlur} labelText="Textbox" name="Text"/>

<ValourTextbox validateOnBlur handleOnChange={this.handleChange} labelText="Textbox Two" name="TextTwo"/>

If, for some reason, you want to validate on blur and on change both, you will have to add the validateOnBlur and validateOnChange properties to the individual input.

//This input with validate both on change and blur, but the validation on blur won't be very noticable!
<ValourTextbox validateOnBlur validateOnChange labelText="Another Box" name="LastBox" />

FAQs

Package last updated on 19 May 2017

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