perscrew / react-simple-form-validator Goto Github PK
View Code? Open in Web Editor NEWA simple library to validate your form fields with React or React Native
A simple library to validate your form fields with React or React Native
Add custom validation function such that users can be able to provide their custom field validator function.
const { } = useValidation({
fieldsRules: {
name: {
validator: (value: string): boolean => {
return boolean;
},
},
},
state: { name },
});
Can it be used for nesting validation (e.g. address.city
)?
I am trying to incorporate multiple validations for a 'multi screen form'. As my form is dynamic, the validation needs to be written for all fields within the same file (unless there is a recommended way to handle this separately).
For example:
useValidation written
Form1
Form2 appears after form1 is validated
Is there a solution to this?
Thanks
When i tried using customize rules, i guess, i need to add customize message for the new rule i created. Otherwise, when validation failed, the app will show error:
const { isFieldInError, getErrorsInField, isFormValid } = useValidation({
fieldsRules: {
name: { required: true, minlength: 5, maxlength: 30, cusR: 'aaa'},
},
rules: {
...defaultRules,
cusR: (format: string, value) => {
return value.indexOf(format) > -1;
}
},
state: { name },
})
TypeError: Cannot read properties of undefined (reading 'replace')
This happened on line 93 on file: services/validator-service.js,
Because no match customized rule name in the default messages map appearantly.
After i add cusomized message (I know i need to add other), the validation failure message will be : "name NaN invalid"
const { isFieldInError, getErrorsInField, isFormValid } = useValidation({
fieldsRules: {
name: { required: true, minlength: 5, maxlength: 30, cusR: 'aaa'},
},
rules: {
...defaultRules,
cusR: (format: string, value) => {
return value.indexOf(format) > -1;
}
},
messages: {
...defaultMessages,
en: {...defaultMessages.en, cusR: "{0} {1} invalid"}
},
state: { name },
})
I found bug on line 91 on File: services/validator-service.js,
evaluate +value
will be 'NaN', if value is undefined.
(function()
{
'use strict';
console.log(+ undefined)
}());
// NaN
I think more condition check need to be add on this part.
I don't know whether my explaination makes sense or not. if not , i am sorry about it.
Overall, this is a greate library, I am glad i found it and thank you for your sharing.
If need more information or other query, please let me know. Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.