Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@surinderlohat/react-form-validation
Advanced tools
Form validation solution for react JS, super easy to use and can handel all the major user cases. ##### Based on the React hooks and reactive programing. #### No extra dependencies pure react js code & lightweight.
Readme
Form validation solution for react JS, super easy to use and can handel all the major user cases.
npm install @surinderlohat/react-form-validation
or
yarn add @surinderlohat/react-form-validation
https://surinderlohat.github.io/react-form-validation/
Method | PARAMS | DESCRIPTION |
---|---|---|
resetToDefault | No | Reset form state to default All fields will be reset to the default state |
getField | fieldKey i.e name or user.name if nested field | Return the specific field instance |
getChangedFields | No | Return fields with initial value and changed value |
clearForm | No | Clear form values and all nested child's |
onSubmit | No | Return from values and error state |
Name | RETURN Type | RETURN VALUE |
---|---|---|
getValues | object | Return form values in same order we have pass |
getErrors | object | Display all errors for each nested field |
hasChanges | boolean | Return true if any field has changes |
Method | TYPE | RETURN VALUE |
---|---|---|
hasChanges | Getter | Return field state i.e it's changed or not |
hasError | Getter | Return error state of the specific field |
isTouched | Getter | if field is touched or not |
errorMessage | Getter | Return error message for current field from |
setValue | Function | Set value of specific field |
getValue | Function | Get value of specific field |
setRules | (newRules: Rules) | Update field rules on the fly |
setError | Function | Set custom error message on specific field |
showErrors | Function | Show error without touching the fields |
Rules
/* Used to identify which rule we are going to use for a field*/
rule: 'min' | 'max' | 'required' | 'same' | 'email' | 'regex' | 'custom' | 'between' | 'range';
/* Rule value used to provide value in rule i.e for min:2 max:10 rule value ruleValue will be ruleValue:2 or 5
ruleValue?: any;
/* Used to provide custom message for each rule */
message?: string;
/* For special cases if we need custom validation then this method will help */
validation?: (field: IField, form?: ReactForm) => string;
import { IFieldObject, useReactForm } from '@surinderlohat/react-form-validation';
import FormField from '../FormField/FormField';
import { Box, Typography, Button, Paper } from '@mui/material';
import { FC } from 'react';
// Fields Rules
const field: IFieldObject = {
name: {
label: 'User Name',
placeholder: 'Enter your Name',
rules: [{ rule: 'required' }],
},
email: {
label: 'Email',
placeholder: 'Enter your email',
rules: [{ rule: 'email', message: 'Email is not valid' }],
},
password: {
label: 'Password',
rules: [{ rule: 'required', message: 'This field is required' }],
},
confirmPassword: {
label: 'Confirm Password',
rules: [{ rule: 'required' }, { rule: 'same', ruleValue: 'password', message: 'Should be same as Password' }],
},
};
const BasicExample: FC = () => {
const form = useReactForm(field);
return (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Paper sx={{ width: '350px', padding: '15px', display: 'grid', gridGap: '15px' }}>
<Typography variant="h5">Basic Signup Validations</Typography>
{Object.keys(field).map(key => (
<FormField key={key} field={form.getField(key)} />
))}
<Button onClick={() => console.log(form.getValues())} disabled={form.hasError} variant="contained">
Save Changes
</Button>
<Typography>Has Changes: {`${form.hasChanges}`}</Typography>
<Typography>Has hasError: {`${form.hasError}`}</Typography>
<Button onClick={() => form.showErrors()} variant="contained">
Show Errors
</Button>
</Paper>
</Box>
);
};
export default BasicExample;
https://codesandbox.io/examples/package/@surinderlohat/react-form-validation
Like this package ? show some love by start this repo
For more packages like this please checkout: https://github.com/surinderlohat
MIT Free Software!
FAQs
Form validation solution for react JS, super easy to use and can handel all the major user cases. ##### Based on the React hooks and reactive programing. #### No extra dependencies pure react js code & lightweight.
The npm package @surinderlohat/react-form-validation receives a total of 0 weekly downloads. As such, @surinderlohat/react-form-validation popularity was classified as not popular.
We found that @surinderlohat/react-form-validation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.