react-native-form-container
Advanced tools
+1
-1
| { | ||
| "name": "react-native-form-container", | ||
| "version": "1.0.42", | ||
| "version": "1.0.43", | ||
| "description": "A form container component for React Native", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
+25
-24
@@ -1,5 +0,5 @@ | ||
| import React, {ReactNode, useCallback, useEffect, useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import {isValidation, checkPasswordOptions} from './Validation'; | ||
| import {FormContainerProps} from 'react-native-form-container'; | ||
| import React, { ReactNode, useCallback, useEffect, useState } from "react"; | ||
| import { View } from "react-native"; | ||
| import { isValidation, checkPasswordOptions } from "./Validation"; | ||
| import { FormContainerProps } from "react-native-form-container"; | ||
@@ -10,8 +10,10 @@ export default function FormContainer(props: FormContainerProps) { | ||
| formContainerRef, | ||
| errorMessageField = 'errorMessage', | ||
| errorMessageField = "errorMessage", | ||
| } = props; | ||
| const [children, setChildren] = useState<ReactNode[] | any>( | ||
| React.Children.toArray(initialChildren), | ||
| React.Children.toArray(initialChildren) | ||
| ); | ||
| const [errors, setErrors] = useState<{[key: string]: string | undefined}>({}); | ||
| const [errors, setErrors] = useState<{ [key: string]: string | undefined }>( | ||
| {} | ||
| ); | ||
| const checkValidation = useCallback((errorData: any) => { | ||
@@ -23,5 +25,5 @@ handleErrorMessage(errorData); | ||
| let isEmpty = true; | ||
| React.Children.forEach(initialChildren, child => { | ||
| React.Children.forEach(initialChildren, (child) => { | ||
| if (React.isValidElement(child)) { | ||
| const childProps = {...child.props}; | ||
| const childProps = { ...child.props }; | ||
| if (childProps.id) { | ||
@@ -33,3 +35,3 @@ let checkValidation = childProps?.validation; | ||
| childProps?.value, | ||
| childProps?.passwordOptions, | ||
| childProps?.passwordOptions | ||
| ); | ||
@@ -41,3 +43,3 @@ if (!result) { | ||
| if ( | ||
| (childProps.required && childProps?.value === '') || | ||
| (childProps.required && childProps?.value === "") || | ||
| childProps.value === undefined | ||
@@ -75,5 +77,5 @@ ) { | ||
| setChildren( | ||
| React.Children.map(initialChildren, child => { | ||
| React.Children.map(initialChildren, (child) => { | ||
| if (React.isValidElement(child)) { | ||
| var childProps = {...child.props}; | ||
| var childProps = { ...child.props }; | ||
@@ -83,19 +85,18 @@ if (childProps.id) { | ||
| let error = errors?.[childProps.id]; | ||
| let validationCheck = childProps?.validation || 'text'; | ||
| let validationCheck = childProps?.validation || "text"; | ||
| if (validationCheck) { | ||
| let result = isValidation( | ||
| childProps?.validation || 'text', | ||
| childProps?.validation || "text", | ||
| childProps?.value, | ||
| childProps?.passwordOptions, | ||
| childProps?.pattern, | ||
| childProps?.pattern | ||
| ); | ||
| console.log('result', result); | ||
| if (!result) { | ||
| let validation = childProps?.validation || 'text'; | ||
| if (validation === 'password') { | ||
| let validation = childProps?.validation || "text"; | ||
| if (validation === "password") { | ||
| let errorOptions = checkPasswordOptions( | ||
| childProps?.passwordOptions, | ||
| childProps?.value, | ||
| childProps?.id, | ||
| childProps?.id | ||
| ); | ||
@@ -108,3 +109,3 @@ let findKeyErrorOptions = Object.keys(errorOptions)[0]; | ||
| let validationOrIdErroMessageField = | ||
| childProps?.value === '' | ||
| childProps?.value === "" | ||
| ? error | ||
@@ -122,3 +123,3 @@ : errors?.[validation] || error | ||
| if ( | ||
| (childProps?.value === '' || | ||
| (childProps?.value === "" || | ||
| childProps?.value === undefined) && | ||
@@ -135,3 +136,3 @@ error | ||
| } | ||
| if (childProps.type === 'checkbox') { | ||
| if (childProps.type === "checkbox") { | ||
| if (!childProps.checked) { | ||
@@ -152,3 +153,3 @@ let error = errors[childProps.id]; | ||
| return child; | ||
| }), | ||
| }) | ||
| ); | ||
@@ -155,0 +156,0 @@ }, [initialChildren, errors]); |
+22
-41
| import { | ||
| ValidationFieldsKeys, | ||
| ValidationPasswordOptions, | ||
| } from 'react-native-form-container'; | ||
| } from "react-native-form-container"; | ||
@@ -52,21 +52,20 @@ export const ValidationFields = { | ||
| passwordOptions?: ValidationPasswordOptions, | ||
| pattern?: RegExp, | ||
| pattern?: RegExp | ||
| ) => { | ||
| if (value === undefined || value === null || value === '') { | ||
| if (value === undefined || value === null || value === "") { | ||
| return false; | ||
| } | ||
| if (validation === 'email') { | ||
| if ( | ||
| !pattern?.test(value) ?? | ||
| !ValidationFields.email.pattern.value.test(value) | ||
| ) { | ||
| if (pattern) { | ||
| if (!pattern?.test(value)) { | ||
| return false; | ||
| } | ||
| } | ||
| if (validation === 'password') { | ||
| if (validation === "email") { | ||
| if (!ValidationFields.email.pattern.value.test(value)) { | ||
| return false; | ||
| } | ||
| } | ||
| if (validation === "password") { | ||
| if (passwordOptions?.lowerCase) { | ||
| if ( | ||
| !pattern?.test(value) ?? | ||
| !ValidationFields.lowerCaseCharacter.pattern.value.test(value) | ||
| ) { | ||
| if (!ValidationFields.lowerCaseCharacter.pattern.value.test(value)) { | ||
| return false; | ||
@@ -76,6 +75,3 @@ } | ||
| if (passwordOptions?.upperCase) { | ||
| if ( | ||
| !pattern?.test(value) ?? | ||
| !ValidationFields.upperCaseCharacter.pattern.value.test(value) | ||
| ) { | ||
| if (!ValidationFields.upperCaseCharacter.pattern.value.test(value)) { | ||
| return false; | ||
@@ -85,6 +81,3 @@ } | ||
| if (passwordOptions?.number) { | ||
| if ( | ||
| !pattern?.test(value) ?? | ||
| !ValidationFields.number.pattern.value.test(value) | ||
| ) { | ||
| if (!ValidationFields.number.pattern.value.test(value)) { | ||
| return false; | ||
@@ -94,6 +87,3 @@ } | ||
| if (passwordOptions?.speacial) { | ||
| if ( | ||
| !pattern?.test(value) ?? | ||
| !ValidationFields.speacialCharacter.pattern.value.test(value) | ||
| ) { | ||
| if (!ValidationFields.speacialCharacter.pattern.value.test(value)) { | ||
| return false; | ||
@@ -106,23 +96,14 @@ } | ||
| } | ||
| if (validation === 'text') { | ||
| if ( | ||
| !pattern?.test(value) ?? | ||
| !ValidationFields.text.pattern.value.test(value) | ||
| ) { | ||
| if (validation === "text") { | ||
| if (!ValidationFields.text.pattern.value.test(value)) { | ||
| return false; | ||
| } | ||
| } | ||
| if (validation === 'phone') { | ||
| if ( | ||
| !pattern?.test(value) ?? | ||
| !ValidationFields.phone.pattern.value.test(value) | ||
| ) { | ||
| if (validation === "phone") { | ||
| if (!ValidationFields.phone.pattern.value.test(value)) { | ||
| return false; | ||
| } | ||
| } | ||
| if (validation === 'number') { | ||
| if ( | ||
| !pattern?.test(value) ?? | ||
| !ValidationFields.number.pattern.value.test(value) | ||
| ) { | ||
| if (validation === "number") { | ||
| if (!ValidationFields.number.pattern.value.test(value)) { | ||
| return false; | ||
@@ -136,3 +117,3 @@ } | ||
| value: string, | ||
| inputId: string, | ||
| inputId: string | ||
| ): { | ||
@@ -139,0 +120,0 @@ password?: boolean; |
21627
-1.44%488
-3.56%