@altiore/form
Advanced tools
Comparing version 0.3.20 to 0.3.21
@@ -5,2 +5,3 @@ import { FieldMeta, ValidateFuncType } from '../@common/types'; | ||
name: string; | ||
defaultValue?: string; | ||
validators?: Array<ValidateFuncType>; | ||
@@ -7,0 +8,0 @@ }; |
@@ -12,8 +12,8 @@ import React from 'react'; | ||
export var SimplestField = function () { return (React.createElement("form", null, | ||
React.createElement(Field, { name: "first", label: "First", validators: [minLength(3)] }), | ||
React.createElement(Field, { name: "second", label: "Second", validators: [minLength(3)] }))); }; | ||
React.createElement(Field, { name: "first", defaultValue: "Default", label: "First", validators: [minLength(3)] }), | ||
React.createElement(Field, { name: "second", label: "Second", defaultValue: "", validators: [minLength(3)] }))); }; | ||
export var InsideFormField = function (_a) { | ||
var onSubmit = _a.onSubmit; | ||
return (React.createElement(Form, { onSubmit: onSubmit }, | ||
React.createElement(Field, { name: "first", label: "First", validators: [ | ||
return (React.createElement(Form, { onSubmit: onSubmit, defaultValues: { first: 'NOT DEFAULT' } }, | ||
React.createElement(Field, { name: "first", label: "First", defaultValue: 'DEFAULT', validators: [ | ||
Joi.string().max(5).min(2).messages({ | ||
@@ -23,3 +23,3 @@ 'string.min': 'Слишком коротко', | ||
] }), | ||
React.createElement(Field, { name: "second", label: "Second", validators: [minLength(3)] }))); | ||
React.createElement(Field, { name: "second", label: "Second", defaultValue: 'test', validators: [minLength(3)] }))); | ||
}; |
import React from 'react'; | ||
import { createField } from '..'; | ||
export var Field = createField(function (props) { | ||
var errors = props.errors, inputRef = props.inputRef, label = props.label, name = props.name; | ||
var defaultValue = props.defaultValue, errors = props.errors, inputRef = props.inputRef, label = props.label, name = props.name; | ||
console.log('Field.render', { | ||
@@ -11,4 +11,4 @@ props: props, | ||
React.createElement("span", null, name), | ||
React.createElement("input", { name: name, ref: inputRef }), | ||
React.createElement("input", { defaultValue: defaultValue, name: name, ref: inputRef }), | ||
React.createElement("span", null, errors[0]))); | ||
}); |
@@ -13,2 +13,3 @@ var __assign = (this && this.__assign) || function () { | ||
import React from 'react'; | ||
import merge from 'lodash/merge'; | ||
import { useValidateInput } from '../../@common/hooks'; | ||
@@ -20,4 +21,4 @@ import { useInput } from './validated-field.hooks'; | ||
var _b = useValidateInput(inputRef, validators, field), errors = _b.errors, setErrors = _b.setErrors; | ||
return React.createElement(component, __assign(__assign(__assign({}, componentProps), (field !== null && field !== void 0 ? field : {})), { errors: errors, inputRef: inputRef, name: name, setErrors: setErrors })); | ||
return React.createElement(component, __assign(__assign({}, merge(componentProps, field)), { errors: errors, inputRef: inputRef, name: name, setErrors: setErrors })); | ||
}; | ||
export var ValidatedField = React.memo(ValidatedFieldComponent); |
{ | ||
"name": "@altiore/form", | ||
"version": "0.3.20", | ||
"version": "0.3.21", | ||
"description": "Form helper for building powerful forms", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
51879
1090