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

calidation

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calidation - npm Package Compare versions

Comparing version 1.12.0 to 1.13.0

23

dist/Form.js

@@ -66,10 +66,23 @@ 'use strict';

submitted: false
}, _this.initialValues = {}, _this.onChange = function (e) {
}, _this.initialValues = {}, _this.transforms = {}, _this.onChange = function (e) {
_this.props.onChange(e);
if (!_this.state.config[e.target.name]) {
var _e$target = e.target,
checked = _e$target.checked,
name = _e$target.name,
type = _e$target.type,
value = _e$target.value;
if (!_this.state.config[name]) {
return;
}
_this.setField(_defineProperty({}, e.target.name, e.target.type === 'checkbox' ? e.target.checked : e.target.value));
var val = type === 'checkbox' ? checked : value;
if (typeof _this.transforms[name] === 'function') {
val = _this.transforms[name](val);
}
_this.setField(_defineProperty({}, name, val));
}, _this.onReset = function (e) {

@@ -173,4 +186,5 @@ if (e) {

}, null);
}, _this.registerSubComponent = function (subComponentConfig, initialValues) {
}, _this.registerSubComponent = function (subComponentConfig, transforms, initialValues) {
_this.initialValues = _extends({}, _this.initialValues, initialValues);
_this.transforms = _extends({}, _this.transforms, transforms);

@@ -191,2 +205,3 @@ _this.setState(function (prevState) {

_this.initialValues = (0, _utilities.removeFrom)(_this.initialValues)(keys);
_this.transforms = (0, _utilities.removeFrom)(_this.transforms)(keys);

@@ -193,0 +208,0 @@ _this.setState(function (prevState) {

9

dist/FormValidation.js

@@ -29,3 +29,4 @@ 'use strict';

initialValues = props.initialValues,
rest = _objectWithoutProperties(props, ['children', 'config', 'initialValues']);
transforms = props.transforms,
rest = _objectWithoutProperties(props, ['children', 'config', 'initialValues', 'transforms']);

@@ -37,3 +38,7 @@ return _react2.default.createElement(

_Validation2.default,
{ config: config, initialValues: initialValues },
{
config: config,
initialValues: initialValues,
transforms: transforms
},
children

@@ -40,0 +45,0 @@ )

@@ -34,3 +34,4 @@ 'use strict';

config: (0, _propTypes.shape)({}).isRequired,
initialValues: (0, _propTypes.shape)({})
initialValues: (0, _propTypes.shape)({}),
transforms: (0, _propTypes.shape)({})
};

@@ -61,9 +62,16 @@

var _props = this.props,
config = _props.config,
initialValues = _props.initialValues,
register = _props.register,
initialValues = _props.initialValues,
config = _props.config;
transforms = _props.transforms;
register(config, Object.keys(config).reduce(function (allFields, field) {
return _extends({}, allFields, _defineProperty({}, field, (0, _utilities.getFirstDefinedValue)(initialValues[field], '')));
register(config, transforms, Object.keys(config).reduce(function (allFields, field) {
var value = (0, _utilities.getFirstDefinedValue)(initialValues[field], '');
if (typeof transforms[field] === 'function') {
value = transforms[field](value);
}
return _extends({}, allFields, _defineProperty({}, field, value));
}, {}));

@@ -115,3 +123,4 @@

fields: {},
initialValues: {}
initialValues: {},
transforms: {}
};

@@ -118,0 +127,0 @@ Validation.propTypes = _extends({}, propTypes, {

{
"name": "calidation",
"version": "1.12.0",
"version": "1.13.0",
"description": "A red hot validation library for React",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -402,56 +402,4 @@ # calidation

##### `children: func.isRequired`
Accepts all of the props from `Form` and `Validation` below.
The `children` function is called with an object with the following props:
```js
{
dirty: object, // Object with all fields isDirty state, keyed per field
errors: object, // object with the same keys as `fields`, but with error messages
fields: object, // object with the form field values, to make controlled components
resetAll: func, // call this to programmatically trigger a full state reset
setError: func, // callback accepting a diff object, updating errors like setState
setField: func, // callback accepting a diff object, updating fields like setState
submit: func, // call this to programmatically trigger a submitted state
submitted: bool, // flag showing whether the form has been submitted once or not
}
```
The `setField` function is used whenever you want to update a field outside of
a typical `change` event. Pass an object with the diff you want to apply (like
React's `setState`), and it will update and reevaluate your form.
##### `config: object.isRequired`
The config object specifies what you want to validate, and which validators to
apply to it.
Each validator can accept an object with a `message` key or - in the case where
you don't have to specify anything other than a validation message - just a
string with the error message.
##### `initialValues: object`
The `initialValues` object lets you specify the initial values of the form
fields. These values are available from the `fields` argument in the `children`
function, which lets you control your form fields.
##### `onSubmit: func`
This callback is fired whenever the form is submitted. That can happen whenever
somebody clicks the submit button, or hits `enter` in the form.
The `onSubmit` function is called with an object with the following props:
```js
{
dirty: object, // Object with all fields isDirty state, keyed per field
errors: object, // Object with all error messages, keyed per field
fields: object, // Object with all field inputs, keyed per field
isValid: bool, // Boolean indicating whether your form is valid or not
resetAll: func, // call this to programmatically trigger a full state reset
setError: func, // callback accepting a diff object, updating errors like setState
}
```
### `Form`

@@ -461,3 +409,3 @@

When you want to wrap a complex form (in conjunction )
When you want to wrap a complex form (in conjunction)

@@ -527,2 +475,21 @@ #### Props

##### `initialValues: object`
The `initialValues` object lets you specify the initial values of the form
fields. These values are available from the `fields` argument in the `children`
function, which lets you control your form fields.
The `transforms` object lets you apply transforms to the value before it
is stored and validated against. Each key should map to a field name and be a function
that receives and returns a value. This is useful if you wish to convert a value's
type or enforce casing.
```js
{
foo: (value) => parseInt(value),
bar: (value) => !!value ? 'YES' : 'NO',
etc: (value) => value.toLowerCase(),
}
```
### `ValidatorsProvider`

@@ -529,0 +496,0 @@

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